Sizeof(char[]) in C

后端 未结 8 1794
情深已故
情深已故 2021-01-17 18:15

Consider this code:

 char name[]=\"123\";
 char name1[]=\"1234\";

And this result

The size of name (char[]):4
The size of n         


        
8条回答
  •  旧巷少年郎
    2021-01-17 18:53

    Because there is a null character that is attached to the end of string in C.

    Like here in your case

    name[0] = '1'
    name[1] = '2'
    name[2] = '3'
    name[3] = '\0'
    
    name1[0] = '1'
    name1[1] = '2'
    name1[2] = '3'
    name1[3] = '4'
    name1[4] = '\0'
    

提交回复
热议问题