C examples for String:char array
Initialize part of an array of elements of type char with a string
#include <stdio.h> int main(void) { char str[40] = "To be"; printf("\nThe message is: %s", str); printf("The character \0 is used to terminate a string."); return 0;/*ww w . ja v a 2s . c om*/ }
The compiler will initialize the first five elements, str[0] to str[4], with the characters of the string constant, and str[5] will contain the null character, '\0'.
Space is allocated for all 40 elements of the array.