I read this question and its answer in a book. But I didn\'t understand the book\'s justification.
Will the following code compile?
What's happening is you're trying to initialize a character array with more characters than the array has room for. Here's how it breaks down:
char str[5];
Declares a character array with five characters.
char str[5] = "fast enough";
The second part '= "fast enough";' then attempts to initialize that array with the value "fast enough". This will not work, because "fast enough" is longer than the array is.
It will, however, compile. C and C++ compilers can't generally perform bounds checking on arrays for you, and overrunning an array is one of the most common reasons for segmentation faults. [edit]As Mark Rushakoff pointed out, apparently the newer ones do throw warnings, for some cases.[/edit] This may segfault when you try to run it, more likely I think the array will simply be initialized to "fast ".