Structure Padding

How can I use Structure padding and I want to re-use the remaining memory further?
ex: struct num {
char ch;
int i;
char s;
};

Editorial / Best Answer

Answered by: Mantu

  • Dec 6th, 2017


By using #pragma pack(1) we can reduce the size of structure.

Code
  1. #pragma pack(1)
  2.  
  3. struct num {
  4.   char ch;
  5.   int i;
  6.   char s;
  7. } n1;
  8.  
  9. printf("Size of num structure is %d ", sizeof(n1));
  10.  

Showing Answers 1 - 1 of 1 Answers

Mantu

  • Dec 6th, 2017
 

By using #pragma pack(1) we can reduce the size of structure.

Code
  1. #pragma pack(1)

  2.  

  3. struct num {

  4.   char ch;

  5.   int i;

  6.   char s;

  7. } n1;

  8.  

  9. printf("Size of num structure is %d ", sizeof(n1));

  10.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions