String in C

Facebooktwitterredditpinterestlinkedinmailby feather

String is a collection of character or group of characters. In array, string of character is terminated by a null value “\0” and enclose between double quote. We can declare string in two ways:

  1. By char array.
  2. By string literal

Let us consider how to declare of string by char array.

There are various types of string functions supported by C language.

String Function Description
strcpy(a1, a2); It is used to copy the string a2 into string a1.
strcat(a1, a2); It is used to concatenate the string a2 onto the end of string a1.
strlen(a1); It is used to find the length of string..
strcmp(a1, a2); It is used to compare twostring and returns 0 if both strings are equal.
strrev() It is used to reverse the sting .
strstr(a1, a2); It is used to return a pointer to the a2 in string a1.

Let us consider an example of string functions.

 Example 1:  strcpy()

Example 2:  strcpy()

Example 3:  strlen()

Example 4:  strcmp()

Example 5:  strrev()

Example 6:  strstr()

Facebooktwitterredditpinterestlinkedinmailby feather

Leave a Comment