Character arrays and String arrays in C++ with examples

Creation of the character array syntax:

See the below sample that we can declare the names or words in the character array

Storing Sequences in Arrays

The program declares a fixed array of characters szExample containing the list of characters.
This array is passed to the function ShowArray() along with its length. The ShowArray()
the function is identical to the displayArray() function along with the length.

The output of the above program is

Creating a string of characters

In C++ the character array ends with the ‘\0’ to know the end of the array

See the below example

The declaration of szExample declares the character array with the extra
null character \0 on the end. The ShowArray program iterates through
the character array until a null character is encountered.

The function ShowArray () is simpler to use than its ShowArray()
predecessor because it is no longer necessary to pass along the length of the
character array. This secret handshake of terminating a character array with
a null is so convenient that it is used throughout C++ language. C++ even gives
such an array a special name.

A string of characters is a null-terminated character array. Confusingly enough,
this is often shortened to simply string, even though C++ defines the separate
type string.