Char declaration

Is the following declaration valid? Why?

char str[8] = "COP 2931";
No,this won't work. either u need to increase the size by 1 ie

char str[9]="COP 2931";

or u need to declare it in the following way:-

char str[8]={'C','O','P',' ','2','9','3','1'};

This is because ,if u declare a string, the compiler needs to place a NULL character at the end.
The NULL tells the compiler that the string is terminated.It is automatically placed by compiler at the end,while declaring a string
No it's not valid.
"COP 2931" is a char array of size 9. The string only has 8 characters but one extra char is needed for the null character '\0' to mark the end of the string.
Okay, thanks :)
Topic archived. No new replies allowed.