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
I agree with Als that you can not initialize at time of defining the structure in C. But you can initialize the structure at time of creating instance shown as below.
In C,
struct s {
int i;
int j;
};
struct s s_instance = { 10 ,20 };
in C++ its possible to give direct value in definition of structure shown as below
struct s {
int i;
s(): i(10)
{
}
};