C99 Structure Designated Initialisers and other value

后端 未结 3 1831
再見小時候
再見小時候 2021-01-17 11:06

I am aware that in C99 you can initialize members of the structure using member name as follows :

struct myStruct
{
 int i;
 char c;
 float f;
};
         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 11:34

    In case of

    struct myStruct = {.f = 10.11, .c = 'a', 6};   
    

    the value 6 which is non-designated initializer will assign to the member just after the member initialized with designated initializer. So, in this case, member f is just after c and hence it will be initialized to 6. i still will be initialized to 0 by default.

提交回复
热议问题