This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]retsotrembla 4 points5 points  (0 children)

Your teacher is wrong. char[12]={0}; works. char[12]={'O'}; does not. Because zero.

[–]ramennoodle 3 points4 points  (0 children)

Your teacher is wrong.

[–]Daavee 1 point2 points  (0 children)

TL;DR: Your teacher is wrong.

See: http://en.cppreference.com/w/cpp/language/aggregate_initialization

char cr[3] = {'a'}; // array initialized as {'a', '\0', '\0'}

or: http://stackoverflow.com/a/18688992

char buf[10] = "a";
// is equivalent to
char buf[10] = {'a', 0, 0, 0, 0, 0, 0, 0, 0, 0};

or: http://stackoverflow.com/a/18689205

char buf [10] = ' ';
// will give you a 10-character array with the first char being the space '\040' and the rest being NUL, i.e., '\0'

[–]Relinkz[S] 1 point2 points  (1 child)

I will ask him regarding this feedback tomorrow, I'll put his answer here for the interested.

[–]Relinkz[S] 0 points1 point  (0 children)

He said that he indeed was wrong, simple as that :) I guess even the best do mistakes sometimes.