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

How do I use strcmp?

632


Are local variables initialized to zero by default in c?

541


write a program to create a sparse matrix using dynamic memory allocation.

4366


What is time complexity c?

560


Explain about block scope in c?

655






What the different types of arrays in c?

609


Can the size of an array be declared at runtime?

599


Explain bitwise shift operators?

623


When we use void main and int main?

579


What is the difference between %d and %i?

586


Explain spaghetti programming?

678


Define Array of pointers.

627


What is function prototype in c language?

606


What is typedf?

662


hi, which software companys will take,if d candidate's % is jst 55%?

1652