As discussed in previous chapters, there is no string data type in C-language. Hence, the group of characters without data type forming a word, can be given individually as an array of characters using
String in C .
A string can be defined as an array of characters which are ended using null character(
\0).To read strings given by user,
%s is used in
scanf function.
Note:
One character is compulsory needed to store '0
'.If not specified '\0
' at the end of array, compiler assigns unknown size and leads to wastage of memory.
Declaration of String in C
String declaration will be similar to array declaration. But here, strings are of
char type.
Eg: char i[5];
Initialization of String in C
C strings can be initialized in various ways.
Eg:[c] char i[]="xyz";
OR
char i[5]="xyz";
OR
char i[]={'x','y','z','\0'};
OR
char i[4]={'x','y','z','\0'};[/c]