The Size and Address of Structure and Unions
#include<stdio.h>
#include<stdlib.h>
struct stag
{
char c;
int i;
float f;
double d;
};
union utag
{
char c;
int i;
float f;
double d;
};
main()
{
struct
stag s;
printf("\n size of
structure=%u", sizeof(struct stag));
printf("\n size of
structure=%u", sizeof(s));
printf("\n address of
structure=%u", &s);
printf("\n address of structure
members: %u %u %u %u", &s.c, &s.i, &s.f, &s.d);
union
utag u;
printf("\n size of
union=%u",sizeof(union utag));
printf("\n size of
union=%u",sizeof(u));
printf("\n address of
union=%u",&u);
printf("\n address of union
members: %u %u %u %u",&u.c,&u.i,&u.f,&u.d);
}
Output:
size of structure=24
size of structure=24
address of structure=2686752
address of structure members: 2686752 2686756 2686760
2686768
size of union=8
size of union=8
address of union=2686744
address of union members: 2686744 2686744 2686744 2686744
No comments:
Post a Comment