Character Arrays (C-style strings)
The c-style string is a character array terminated with a null character “\0”.
Hence we can define an array of type char and the dimensions or size of the arrays
and then we can initialize it to a string or array of characters.
Note that it’s the compiler that terminates a string with a null character, so if
we initialize the character array with a string (in the double quote “”) then we
need to leave extra space for the null character while declaring the size of an
array.
Let’s take some Examples of declaring and initializing character arrays.
char firstStr[] = "This is Cstyle string";
char secStr[100] = {'s','o','f','t','w','a','r','e','
','t','e','s','t','i','n','g',' ','h','e','l','p','\0'};
char thirdStr[] = {'h','e','l','l','o','\0'};
All the above definitions are valid C-style string definitions in C++. Note that we
can either declare the actual size or we can leave the size blank so that the
compiler can accommodate the size depending on the string that we initialized.