Friday, May 30, 2014

WRITE A PROGRAMME TO COMPARE THE MEMORY ALLOCATIONS BETWEEN STRUCTURE AND UNION VARIABLE

#include<stdio.h>
#include<conio.h>
void main()
{
typedef union
{
int roll;
char grade;
float per;
}uni1;

typedef struct
{
int roll;
char grade;
float per;
}str1;

uni1 u1;
str1 s1;
clrscr();
printf("\nSTRUCTURE");
printf("\nsize of s1 is %d",sizeof(s1));
printf("\naddress of s1 is %u",&s1);
printf("\naddress of s1.roll is %u",&s1.roll);
printf("\naddress of s1.grade is %u",&s1.grade);
printf("\naddress of s1.per is %u",&s1.per);

printf("\nUNION");
printf("\nsize of u1 is %d",sizeof(u1));
printf("\naddress of u1 is %u",&u1);
printf("\naddress of u1.roll is %u",&u1.roll);
printf("\naddress of u1.grade is %u",&u1.grade);
printf("\naddress of u1.per is %u",&u1.per);
getch();
}

No comments:

Post a Comment