Am 24.02.2010, 20:55 Uhr, schrieb Dag-Erling Smørgrav <[email protected]>:

Why is there a 0 after the 'i'?  Because when you write "abcdefghi", the
compiler actually stores "abcdefghi\0".  That's the definition of
"string" in C: a sequence of characters immediately followed by a 0.  If
you don't want the 0 there, you have to do something like this:

    char a[9] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' };

  char a[9] = "abcdefghi";

suffices. The compiler knows there isn't room for the terminal '\0' and omits it.

  char a[] = "abcdefghi";

would append the implicit \0 and reserve 10 bytes for a.

but then you don't have a string, just an array of 9 chars.

Not that the compiler itself could/would tell the difference after initialization, or that it would even care. It's the library functions that expect strings that care about the \0.

Beyond that, I recommend a C book to Andrey.

--
Matthias Andree
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"

Reply via email to