Skip to content

Instantly share code, notes, and snippets.

@raminfp raminfp/Padding.c
Created Sep 28, 2018

Embed
What would you like to do?
#include <stdio.h>
#include <string.h>
struct struc1
{
int a; int b;
char c1;
char c2;
float f;
};
struct struc2
{
int a;
char c1;
int b;
char c2;
float f;
};
#pragma pack (1)
struct struc3
{
int a;
char c1;
int b;
char c2;
float f;
};
int main()
{
struct struc1 s1;
struct struc2 s2;
struct struc3 s3;
printf("\nsize of s1 in bytes : %u", (int)sizeof(s1));
printf ( "\n Address of a = %p", &s1.a );
printf ( "\n Address of b = %p", &s1.b );
printf ( "\n Address of c1 = %p", &s1.c1 );
printf ( "\n Address of c2 = %p", &s1.c2 );
printf ( "\n Address of f = %p", &s1.f );
printf("\n\nsize of s2 in bytes : %u", (int)sizeof(s2));
printf ( "\n Address of a = %p", &s2.a );
printf ( "\n Address of b = %p", &s2.b );
printf ( "\n Address of c1 = %p", &s2.c1 );
printf ( "\n Address of c2 = %p", &s2.c2 );
printf ( "\n Address of f = %p ", &s2.f );
printf("\n\nsize of s3 in bytes : %u", (int)sizeof(s3));
printf ( "\n Address of a = %p", &s3.a );
printf ( "\n Address of b = %p", &s3.b );
printf ( "\n Address of c1 = %p", &s3.c1 );
printf ( "\n Address of c2 = %p", &s3.c2 );
printf ( "\n Address of f = %p \n", &s3.f );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.