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
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
Eg: char i;
Initialization of String in C
C strings can be initialized in various ways.
Eg:[c] char i="xyz";