sizeof "string"

Morris Keesan keesan at bbncca.ARPA
Sat Feb 11 01:18:54 AEST 1984


----------------------------

    slb at inuxh.UUCP (Stephen Browning) asks,

>	Is "Hello\0, world." a string, or is it two strings?
>	Put another way, is '\0' a legal character to embed
>	within a string?

The answer is "Yes, of course," to both questions.  Section 2.5 of the C
Reference Manual (p. 181 of K&R) says "A string is a sequence of characters
surrounded by double quotes," and "The compiler places a null byte \0 at the end
of each string so that programs which scan the string can find its end." This
puts absolutely no restrictions on the contents of a string, except that the
last character will always be '\0'.  The idea that a NUL character always
indicates the end of a string is strictly a matter of convention.  One should
not confuse definitions used by library routines with the definition of a
language.  In particular, the manual page string(3), which says, "The arguments
. . . point to strings (arrays of characters terminated by a null character),"
should be ignored for the purposes of any discussion of the definition of C. 
-- 
					Morris M. Keesan
					{decvax,linus,wjh12}!bbncca!keesan
					keesan @ BBN-UNIX.ARPA



More information about the Comp.lang.c mailing list