Is char a[3] = "abc"; legal? What does it mean?
It is legal in ANSI C (and perhaps in a few pre-ANSI systems), though useful only in rare circumstances. It declares an array of size three, initialized with the three characters 'a', 'b', and 'c', without the usual terminating '\0' character. The array is therefore not a true C string and cannot be used with strcpy, printf %s, etc.
Most of the time, you should let the compiler count the initializers when initializing arrays (in the case of the initializer "abc", of course, the computed size will be 4).
References:
ANSI Sec. 3.5.7
ISO Sec. 6.5.7
H&S Sec. 4.6.4 p. 98
Read sequentially: prev next up top
This page by Steve Summit // Copyright 1995 // mail feedback