"AA"
is indeed 'AA\0'
, two characters A
and a '\0'
(being a zero byte).
Conventionally, in C and C++, writing "something"
will automatically add a 0-byte after the characters of something
. Thus the size in bytes of "something"
is 10.
In the array, "AA"
gives the address of the string "AA", and NULL gives an address zero (all bytes of an address are set to zero).
It is fine to define the array like
char *array[] = { "AA", "BB" };
Adding a NULL
merely adds an item to the array, being a null-address (zero). But syntactically both are correct.
However, some functions (for instance from a library), might require to add a NULL
after a list of values. To indicate this is the last argument (some functions of the exec family for instance, see this answer)