Declaring and initializing string variables

C does not support string as a data type. However, it allows us to represent strings as character arrays. In C, therefore, a string variable is any valid C variable name and is always declared as an array of characters. 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. Some example are :

char city[10];
char name[30];

When the compiler assign a character string to a character array, it automatically suplies a null character ('\0') at the end of the string. Therefore, The size should be equal to the maximum number of characters in the string plus one.

Like numeric arrays, character arrays may be initialized when they are declared. C permits a character array to be initialized in either of the following two forms.

char city [9] = "NEW YORK" ;
char city [9] = {'N','E','W','',Y','O','R','K','\0'};