About default C struct values, what about this code?

后端 未结 8 1504
时光说笑
时光说笑 2020-12-31 15:27

I\'m trying to create structs with default values. I don\'t know how to accomplish this because every code that I see, is about initialising, and I would it for the natural

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 16:08

    in C (pre C99) the following also works:

    #include 
    typedef struct
    {
        int a;  
        int b;
        int c;
     } HELLO;
    
    int main()
    {
    HELLO a = {1,2,3};
    
    printf("here: %d %d %d\n",a.a,a.b,a.c);
    exit(1);
    }
    

    See codepad

提交回复
热议问题