default value for struct member in C

后端 未结 16 2249
-上瘾入骨i
-上瘾入骨i 2020-11-27 10:53

Is it possible to set default values for some struct member? I tried the following but, it\'d cause syntax error:

typedef struct
{
  int flag = 3;
} MyStruct         


        
16条回答
  •  醉话见心
    2020-11-27 11:34

    You can implement an initialisation function:

    employee init_employee() {
      empolyee const e = {0,"none"};
      return e;
    }
    

提交回复
热议问题