Structure - Memory Allocation - Structure Padding

Published: 25 April 2020
on channel: Solution Manual
80
2

// STRUCTURES AND UNIONS

// TOPIC ==== STRUCTURE PADDING

#include stdio.h
int main()
{
struct test
{
int a; // 4 bytes allocated for a variable
int b; // 4 bytes allocated for b variable
char c[2]; // it will also give the same result but empty space is reduced from 3 to 2 // 1 byte allocated for c variable:::::: By definition Total Size is : 4+4+1=9
}t;

printf("%d",sizeof(t)); // but we got 12 as output this is due to padding space .
return 0;
}

// OUTPUT IS 12

// 4 bytes for a
// 4 bytes for b
// 1 byte for c
// 3 bytes for empty space

// total = 4+4+1+3=====12


On this page of the site you can watch the video online Structure - Memory Allocation - Structure Padding with a duration of hours minute second in good quality, which was uploaded by the user Solution Manual 25 April 2020, share the link with friends and acquaintances, this video has already been watched 80 times on youtube and it was liked by 2 viewers. Enjoy your viewing!