Pointer to a string acts similar to that of a pointer to array, here the pointer variable holds the address of the first-string variable and hence the required operation is executed.
Syntax:
char ch[5]=”ABCD”;
char *ptr=ch;

The above description depicts the pointer to a string where the first address value 1000 is stored in the pointer variable.
The next address is incremented by 1 as each character of a string holds a value of 1 memory space. This 1000 or the first address is used to access the string.
Let’s see an example how pointer is used to access an string:
#include<stdio.h> int main() { char ch[10]="POINTER"; char *ptr=ch; while(*ptr!='\0') { printf("%c",*ptr); ptr++; } return 0; }
Here in the above program the address of the first-string variable is stored in the pointer variable as the string is initialised in it.
The pointer keeps on incrementing with 1 as each character holds a value of 1 memory space until it reaches to the end or NULL and keeps on printing the string by invoking the pointer, then the loop is terminated.
Output:
Hence, we have reached the end of the topic. Hope we have cleared all your doubts.
Please comment and share this article if you find helpful and WhatsApp me to improve this article.