I have a simple code in C to see if three same char arrays all end with '\0'
:
int main(){
char a[4] = "1234";
char b[4] = "1234";
char c[4] = "1234";
if(a[4] == '\0')
printf("a end with '\\0'\n");
if(b[4] == '\0')
printf("b end with '\\0'\n");
if(c[4] == '\0')
printf("c end with '\\0'\n");
return 0;
}
But the output shows that only array b ends with terminator '\0'
. Why is that? I supposed all char arrays have to end with '\0'
.
Output:
b end with '\0'