Char array initialization dilemma

后端 未结 3 1285
予麋鹿
予麋鹿 2020-12-07 03:53

Consider following code:

// hacky, since \"123\" is 4 chars long (including terminating 0)
char symbols[3] = \"123\";

// clean, but lot of typing
char symbo         


        
3条回答
  •  感动是毒
    2020-12-07 04:22

    If your array is only 3 chars long, the first line of code is identical to the second line. The '\0' at the end of the string will simply not be stored. IOW, there is nothing "dirty" or "wrong" with it.

提交回复
热议问题