Confusion about array initialization in C

后端 未结 7 1315
不知归路
不知归路 2020-12-12 18:13

In C language, if initialize an array like this:

int a[5] = {1,2};

then all the elements of the array that are not initialized explicitly w

7条回答
  •  半阙折子戏
    2020-12-12 18:28

    My Understanding is a[2]=1 returns value 1 so code becomes

    int a[5]={a[2]=1} --> int a[5]={1}
    

    int a[5]={1} assign value for a[0]=1

    Hence it print 1 for a[0]

    For example

    char str[10]={‘H’,‘a’,‘i’};
    
    
    char str[0] = ‘H’;
    char str[1] = ‘a’;
    char str[2] = ‘i;
    

提交回复
热议问题