How to avoid structure padding in C?

Answer Posted / lakshman naganoor

By #pragma

Example:
#pragma pack(push,1)
struct mystruct_A {
int b;
short d;
double c;
char m;
};
#pragma pack(pop)

main()

{
printf("size of structure mystruct_Ad is %d\n",sizeof
(struct mystruct_A));
}

size of structure mystruct_Ad is 15

Note:size of structure mystruct_Ad without using #pragma

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the use of function toupper() with and example code?

647


What functions are used for dynamic memory allocation in c language?

594


swap 2 numbers without using third variable?

656


write a program fibonacci series and palindrome program in c

628


Write a program to reverse a given number in c?

592






Explain enumerated types in c language?

598


What does #pragma once mean?

679


Define C in your own Language.

633


How to explain the final year project as a fresher please answer with sample project

463


Write a program to reverse a given number in c language?

613


What is #define size in c?

640


what is the structure pointer?

1640


What is use of null pointer in c?

563


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

558


What is the size of structure pointer in c?

608