Tuesday, 5 June 2018

STRUCTURE - 3 (Structure padding)


                     

              "Allocating the memory for a structure variable more then the required memory is called structure padding, that extra byte of memory is called hole in a structure;"






Some more examples:

struct A
         {
         int a;
         char c;
         float f;
         };
Size of struct A should be 9 but it is 12, that is known as structure padding and extra 3 byte are known as hole.

For removing the hole we can use below keyword:

#pragma pack(1)   //only in GCC compiler