Consider this code:
char name[]=\"123\";
char name1[]=\"1234\";
And this result
The size of name (char[]):4
The size of n
As Michael pointed out in the comments the strings are terminated by a zero. So in memory the first string will look like this
"123\0"
where \0
is a single char and has the ASCII value 0. Then the above string has size 4.
If you had not this terminating character, how would one know, where the string (or char[]
for that matter) ends? Well, indeed one other way is to store the length somewhere. Some languages do that. C doesn't.