Say for instance I declare a char array with all values set to zero in the following fashion:
char array[4] = {0};
If I assign it values, for instance:
array[0] = 'A';
array[1] = 'B';
array[2] = 'C';
Do I need to null terminate the array like so?:
array[3] = '\0';
or does the operation char array[4] = {0}
null terminate previous to any assignment?
No.
'\0'
is just a fancy way of writing0
. It's a way to write self-documenting code referring to the null terminator specifically, out of tradition. (It's actually just a zero written as an octal escape sequence, of all things.)Since you already set all items to
0
, there is no need for an extra\0
.