A String can be defined as an array of characters that are terminated with null character
\0. A compiler assigns the null character if the developer does not specify. To read strings given by user,
%s is used in
scanf function.
CPP Strings takes the help of '
char'.
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, CPP Strings are of
char type.
Eg:
char i[5];
Initialization of String in C
C strings can be initialized in various ways.
Eg:
char i[]="xyz";
OR
char i[5]="xyz";
OR
char i[]={'x','y','z','\0'};
OR
char i[4]={'x','y','z','\0'};