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
Can you think of a logic behind the game minesweeper.
What do you mean by keywords in c?
What is pass by value in c?
what is the function of pragma directive in c?
explain what is a newline escape sequence?
What is difference between static and global variable in c?
Explain how can you determine the size of an allocated portion of memory?
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
What is the collection of communication lines and routers called?
What are integer variable, floating-point variable and character variable?
What is difference between constant pointer and constant variable?
Why do we use int main instead of void main in c?
What is typeof in c?
Is it possible to execute code even after the program exits the main() function?
What is pointer to pointer in c with example?