Memory layout for nested structure in c

Viewed 2582

I understand the structure's concept in C. I also understand how the structure is stored in memory. So I have created follwoing stuff:

  struct tag1 {
      char a;
      int b;
  }var1;

The size of the structure is 8 bytes(in gcc).

Memory layout example.

 -----------
|  |  |  |  | ---> char a (only 1 byte is used and remaining 3 bytes are padding)
 -----------
|  |  |  |  | ---> int b (4 byte is used)
 -----------

Now i have some doubt in this sample program. How the nested structure is stored in memory.

  struct tag1{
      int a;
      struct tag2{
          long b;
      }var1;
  }var2;
3 Answers
Related