What is structure padding & expalain wid example
what is bit wise structure?



What is structure padding & expalain wid example what is bit wise structure?..

Answer / pankaj saraf

Padding is actually a compiler optimization technique, which
fill up the area between to member to make multiples of 4
bytes (32 bits). Only combination chars/ shorts int/ both ca
e able to create a 32 bytes. Compiler actually will skip to
check the size the variable and fetch the whole 4 bytes in
data fetch operation. this will provide the aligned data to
MP in Single CPU cycle.
There is a Pragma directive, which override the compiler and
results the structure size with equal to size of variables.

Example:

Struct item {
int item;
char type;
};

Sizeof (struct item) = 8 bytes

Struct item {
int item;
char type[2];
short int value;
};
Sizeof (struct item) = 8 bytes

Struct item {
int item;
char type[3];
short int value;
};
Sizeof (struct item) = 12 bytes
one byte padded after "type" and 2 byes padded after value.



Bit-Wise: As far as I remember, it maintains a ARRAY of
int/char/bits equal to the number of elements defined inside
. The bit sets if some data is initialized with some value.
I am not sure on this.

Is This Answer Correct ?    4 Yes 1 No

Post New Answer

More C Interview Questions

How do you generate random numbers in C?

0 Answers  


What are the advantage of c language?

0 Answers  


how to find the size of the data type like int,float without using the sizeof operator?

13 Answers  


Write a simple code fragment that will check if a number is positive or negative.

0 Answers  


a=0; while(a<5) printf("%d\n",a++); how many times does the loop occurs? a.infinite b.5 c.4 d.6

7 Answers   TCS,






What does the format %10.2 mean when included in a printf statement?

0 Answers  


void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result for all case

9 Answers   Accenture, TCS,


What does %d do?

0 Answers  


How main function is called in c?

0 Answers  


Explain how can I avoid the abort, retry, fail messages?

0 Answers  


What is the difference between declaring a variable and defining a variable?

0 Answers  


write a program without using main function?

2 Answers   TCS,


Categories