C++: size of a char array using sizeof

arrays, c++, sizeof, string

Solution

C-strings contain a null terminator, thus adding a character.

Essentially this:

char a2[] = {'a','b','c','\0'};

Problem

Look at the following piece of code in C++: ``` char a1[] = {'a','b','c'}; char a2[] = "abc"; cout << sizeof(a1) << endl << sizeof(a2) << endl; ``` Though `sizeof(char)` is 1 byte, why does the output show `sizeof(a2)` as 4 and not 3 (as in case of `a1`)?

Original source