by Dinesh Thakur Category: Function and Pointer

Strings are character arrays terminated by null character. Pointer to a single string may be declared in the same way as the pointer to a one-dimensional array.

char Name[] = "Dinesh";

char *ptrname ;

ptrname = Name;

Though the declaration and initialization of a pointer to a string is similar to that of a pointer to an array, the difference lies in the input/output. String may be taken as a single object for input and output and its characters may also be treated like elements of an array.

Illustrates pointer to strings

#include<stdio.h>

int main()
{
  char Name[] = "Dinesh";
  char* ptrname = Name;
  clrscr();
  printf("Name = %s\n",Name);
  printf("Name via ptrname = %s\n", ptrname);
  return 0;
}

Pointers to Strings in C



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles