Assigning strings to arrays of characters

后端 未结 9 1378
小鲜肉
小鲜肉 2020-11-22 15:03

I am a little surprised by the following.

Example 1:

char s[100] = \"abcd\"; // declare and initialize - WORKS

Example 2:



        
9条回答
  •  无人共我
    2020-11-22 15:49

    Note that you can still do:

    s[0] = 'h';
    s[1] = 'e';
    s[2] = 'l';
    s[3] = 'l';
    s[4] = 'o';
    s[5] = '\0';
    

提交回复
热议问题