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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we declare a function inside a function in c?

590


Differentiate between a for loop and a while loop? What are it uses?

675


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

1633


What is the modulus operator?

736


Is it possible to have a function as a parameter in another function?

599






How many main () function we can have in a project?

614


What is use of bit field?

774


What is the importance of c in your views?

596


Can a pointer point to null?

589


When can a far pointer be used?

588


What is #include called?

568


How are structure passing and returning implemented?

592


What is sorting in c plus plus?

565


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

759


What is the use of c language in real life?

530