structure in c language code example

Example 1: C structure

struct struct1 {
  int a;
  char b;
}
typedef struct struct2 {
  int a;
  char b;
} name;

void main()
{
  struct struct1 var1;
  name			 var2;
  
  var1.a = 10;
  var2.b = 'c';
}

Example 2: declare structure in c

struct num{
 int a ;
 int b;
};

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

Example 3: Structure of Structs in c

The basic structure

Example 4: Structure of Structs in c

struct [structure_tag]
{
    //member variable 1
    //member variable 2
    //member variable 3
    ...
}[structure_variables];

Tags:

C Example