Overview of Strings

In C language the group of characters, digits, and symbols enclosed within quotion marks are called as string. The string is always declared as character arrays. In other words character arrays are called Strings.

A string constant is a one-dimensional array of characters terminated by a null ( ‘’ ).

Each character in the array occupies one byte of memory and the last character is always null character.

‘’ is called null character.

‘’ & ‘0’ are not same because ASCII value of null is 0 and ASCII value of  '0' is 48.


Declaration and Initialization of String:-

The string can be initialized as follows.

 char name[]="CSE";

The C compiler insets the null () character automatically at the end of the string. So initialization of null character is not essential.

Character arrays can be initialized as follows.

 char name[]={'C','S','E',''};


String Constant:-

String constant is a sequence of character enclosed by " " (double quotes). Embedded space are significant.


Standard Library String Functions

Sr.No Function Name  Use
1 strlen Finds length of a string
2 strlwr Converts a string to lowercase
3 strupr Converts a string to uppercase
4 strcat Appends one string at the end of another
5 strncat Appends first n characters of a string at the end of another
6 strcpy Copies a string into another
7 strcmp Compares two strings
8 strchr Finds first occurrence of a given character in a string
9 strdup Duplicates a string
10 strrev Reverses string