/* B10. C Program to demonstrate the difference between structure and union */
#include<stdio.h>
struct mystruct
{
int i;
float f;
};
union myunion
{
int i;
float f;
};
void main()
{
struct mystruct s;
union myunion u;
clrscr();
printf("Size of the struct mystruct=%d\n", sizeof(s));
printf("Size of the union myunion=%d\n", sizeof(u));
s.i=10;
s.f=3.45;
printf("st.i=%d\n",s.i);
printf("st.f=%f\n",s.f);
u.i=20;
printf("ut.i=%d\n",u.i);
u.f=8.25;
printf("ut.f=%f\n",u.f);
getch();
}
Search This Blog
Wednesday, 2 March 2022
B10. C Program to demonstrate the difference between structure and union.
Labels:
NEP_C_Programs
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment