How to assign a C struct inline?

前端 未结 2 1303
一个人的身影
一个人的身影 2021-02-02 05:32
typedef struct {
    int hour;
    int min;
    int sec;
} counter_t;

And in the code, I\'d like to initialize instances of this struct without explici

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-02 06:08

    Initialization:

    counter_t c = {10, 30, 47};
    

    Assignment:

    c = (counter_t){10, 30, 48};
    

    The latter is called a "compound literal".

提交回复
热议问题