I am new to the C programming language and leaning it recent days. I am little confused on how termination character works and why do we need it. When I look at some documentation on the web, they usually state when we initialize the char array the last character must be '\0'. However when I don't insert it to the end of char array it seems also compile and works well. For example:
char test[4] = "test";
printf("%s\n", test );
printf("%lu\n", strlen(test) );
it compiles, print out the value properly and also strlen return the correct value which means the compiler knows where is the last character in the char array. Then why do we have to add '\0' at the end. Is this JUST the convention? Or there is something else?
Thanks.