Write a C Program to Print String using Pointer

Write a C Program to Print String using Pointer


 #include <stdio.h>
 int main()
{
    char str[100];
    char *p;



    printf("Enter any string: ");
    fgets(str, 100, stdin);

    /* Assigning the base address str[0] to pointer
     * p. p = str is same as p = str[0]
     */
    p=str;

    printf("The input string is: ");
    //'\0' signifies end of the string
    while(*p!='\0')
        printf("%c",*p++);

    return 0;
 }
          

Output:

 Enter any string: Aimtocode
 The input string is: Aimtocode

 --------------------------------