0
Q:

how to initialize a struct in c

struct num{
 int a ;
 int b;
};

int main()
{
    struct num n;
    //accessing the elements inside struct
    n.a=10;
    n.b=20;
}

0
typedef struct MY_TYPE {
  bool flag;
  short int value;
  double stuff;
} MY_TYPE;

void function(void) {
  MY_TYPE a;
  ...
  a = { true, 15, 0.123 }
}
0

New to Communities?

Join the community