Sunday, 8 September 2013

C char array initialization

C char array initialization

I'm not sure what will be in the char array after initialization in the
following ways.
1.char buf[10]; buf == '';
2. char buf[10]; buf == ' ';
3. char buf[10]; buf == 'a';
For case 2, I think buf[0] should be ' ', buf[1] should be '\0', and from
buf[2] to buf[9] will be random content.
For case 3, I think buf[0] should be 'a', buf[1] should be '\0', and from
buf[2] to buf[9] will be random content. Is that correct?
And for the case 1, what will be in the buf? buf[0] == '\0' and from
buf[1] to buf[9] will be random content?
Thank you!

No comments:

Post a Comment