We are transitioning C code into C++.
I noticed that the following code is well defined in C,
int main(){
//length is valid. '\0' is ignored
char str[3]="abc";
}
as it is stated in Array initialization that:
"If the size of the array is known, it may be one less than the size of the string literal, in which case the terminating null character is ignored."
However, if I were to build the same code in C++, I get the following C++ error:
error: initializer-string for array of chars is too long
[-fpermissive] char str[3]="abc";
I'm hoping someone can expound on this.
Questions:
Is the code example valid in all C language standards?
Is it invalid in all C++ language standards?
Is there a reason that is valid in one language but not another?