logo
Pointer and Character array In C Language
Pointer can also be used to create strings. Pointer variables of char type are treated as string. Pointers are very useful in accessing character arrays. The character strings can be assigned with a character pointer.

 Example : 
  char array[ ] = “Love India”;        //array version
    char *str = "Hello";

This creates a string and stores its address in the pointer variable str. The pointer str now points to the first character of the string "Hello". Another important thing to note that string created using char pointer can be assigned a value at runtime.

           char *str;
           str = "hello";   //Legal
          The content of the string can be printed using printf() and puts().
           printf("%s", str);
          puts(str);

Notice that str is pointer to the string, it is also name of the string. Therefore we do not need to use indirection operator *.
  Program : The following program is an example of pointer and character array.
#include<stdio.h>
 #include<conio.h>
 main()
  {
  int i;
  char *p= “ Love India”;
  clrscr();
  while (*p! = “\0”)
    {
   printf (“ %c “, *p);
   p++;
    }
 } 
Output :

Love India