character sequences

According to http://www.cplusplus.com/doc/tutorial/ntcs/
"
char myword[] = { 'H', 'e', 'l', 'l', 'o', '\0' };
char myword[] = "Hello";
In both cases, the array of characters myword is declared with a size of 6 elements of type char: the 5 characters that compose the word "Hello", plus a final null character ('\0'), which specifies the end of the sequence and that, in the second case, when using double quotes (") it is appended automatically."

However there are examples where word array is declared as :
char myword[] = { 'H', 'e', 'l', 'l', 'o' };
Is syntactically correct?? If yes, what is the size of myword? and does '\0' append by compiler automatically?
And is char myword[] = "abc" same as
char myword[] = {'a','b','c','\0'} or is it same as char myword[] = {'a','b','c'} ??
Last edited on
Yes, it is syntactically correct.
Size is 5 bytes.
No, the null is not appended.
"
Size is 5 bytes.
No, the null is not appended. "

Is'nt it a compulsion that the character arrays should end with a null character? Please explain a bit why is its size 5 and not 6? and null should be added to all string literals as per my class, then why is null not appended LIKE in case of char myword[] = "abc" ( where null be be added automatically)

Last edited on
Quoted literals (double quotes) and an array of single characters are two different things.

Quoted strings are recognized and treated specially by the compiler.
@AbstractionAnon@ Thanks .. seems as they are different, null character rules only apply to " " things :)
Last edited on
Topic archived. No new replies allowed.