Structure Padding Calculator
C
Easy
5 views
Problem Description
Create a structure with char, int, char, or double members. Use sizeof() to find the total size. Then calculate it manually, taking into account padding. Why does the compiler add padding?
Official Solution
#include <stdio.h>
struct Example {
char a; // 1 byte
int b; // 4 bytes
char c; // 1 byte
double d; // 8 bytes
};
int main() {
printf("Size of structure = %lu bytesn", sizeof(struct Example));
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!