Created
September 28, 2018 16:21
-
-
Save raminfp/33cb1c3096f8f397bcee7b9809ffab24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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