Tuesday 13 April 2021

Union in C and C++

 #include<iostream.h>

#include<conio.h>

union Book

{

char code;

int pages;

float price;

};

int main()

{

clrscr();

Book b;

b.code='A';

b.pages=400;

b.price=150;

cout<<b.code<<endl;

//b.pages=500;

cout<<b.pages<<endl;

//b.price=300;

cout<<b.price<<endl;

cout<<sizeof(b);

int *p=(int*)100;


getch();

return 0;

}

No comments:

Post a Comment