C Strings


  • Initializing Strings
  • Reading Strings from the terminal
  • Writing strings to screen
  • Arithmetic operations on characters
  • String operations (string.h)
  • String functions

String functions

  • strlen()
  • strcat()
  • strcmp()
  • strcmpi()
  • strcpy()
  • strlwr ()
  • strrev()
  • strupr()


A string variable is any valid C variable name & is always declared as an array. The general form of declaration of a string variable is
Char string_name[size];

The size determines the number of characters in the string name.
	char month[10]; 
	char address[100]; 

The size of the array should be one byte more than the actual space occupied by the string since the complier appends a null character at the end of the string.

Initializing Strings

/*String.c string variable*/ #include < stdio.h > main() { char month[15]; printf (“Enter the string”); gets (month); printf (“The string entered is %s”, month); }

Program description

In this example string is stored in the character variable month the string is displayed in the statement.
printf(“The string entered is %s”, month”); It is one dimension array. Each character occupies a byte. A null character (\0) that has the ASCII value 0 terminates the string.
The figure shows the storage of string January in the memory recall that \0 specifies a single character whose ASCII value is zero.
J A N U A R Y \0 Character string terminated by a null character ‘\0’.

Make Comments..!!

Oops!! No posts from user.