String Pointers In C Language

String Definition

Normally, A String is a sequence of characters stored in an array. A string always ends with null ('\0') character.

Similar like arrays, string names are "decayed" to pointers. Hence, you can use pointers to manipulate elements of the string.

Suppose we have a string ‘C Pointer to be stored in a variable in the program. Then we create an array of character to hold this value. Hence we declare and initialize it as follows:

char chrString [] = {‘W’,’e ’,’l ’,’c ’,’o ’,’m ’,’e ’,’\0’};
char chrString [] = “Welcome”;

Example :


 String value pointed by pointer is :
 C PointersNew copied string pointer is :
 C Pointers

Example 2:


 Enter any string: welcome to aimtocode
 The input string is: welcome to aimtocode