Home >>C Tutorial >C Strings

C Strings

Strings in C language

The strings in the C language can be defined by various methods but the best definition is that it is basically a one-dimensional array of characters that is terminated by a null that is represented by the symbol (‘\0’). In order to manipulate the text that are basically the words or sentences, the strings or the character array is used. There are rules everywhere and in case of strings there is a rule that the last character always must be zero and one byte of memory is occupied by each character in the array. In order to identify where the strings is getting to the end, the use of the termination character ('\0') is then necessary in a string.

In order to declare the string there are two ways in the C language:

  • char array
  • string literal

Difference between char array and string literal

There are basically two known differences that are the main differences between the char array and literal.

  • There is a need to add the null character '\0' by the user at the end of the array on the other hand in the case of the character array, the compiler append it internally.
  • The string literal is not allowed to be reassigned to another set of characters and on the other hand the characters of the array can be reassigned.

Here are different functions of the strings:

Function Description
strlen() This function returns the length of the provided string.
strcpy() This function copies the source string in the destination.
strcat() The result is returned to first string after this function concatenates the two functions.
strcmp() This function compares the two strings and if both strings are equal then returns 0.
strrev() This function returns the reverse of the provided string.
strlwr() This function returns the characters of the strings in lowercase.
strupr() This function returns the characters of the strings in uppercase.
strstr() This function generally return the substring from first match till the last character.