-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct-union.cpp
More file actions
44 lines (43 loc) · 1020 Bytes
/
Copy pathstruct-union.cpp
File metadata and controls
44 lines (43 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;
// ********Struct*******
typedef struct employee
{
/* data */
int eid;
char favAlphabet;
double sal;
}ep;
/* OR
struct employee
{
int eid;
char favAlphabet;
double sal;
}
int main(){
ep anirudh;
// OR struct employee anirudh;
anirudh.eid=22;
anirudh.favAlphabet='s';
anirudh.sal=25000;
cout<<anirudh.eid<<endl;
cout<<anirudh.favAlphabet<<endl;
cout<<anirudh.sal<<endl; */
// *******Union*******
union money{
int rice;
int car;
float pounds;
};
// ******only one of the data can be used(executed) when using union unlike struct and the previous data will be overwritten******
int main(){
union money m1;
m1.rice=22;
m1.car=77;
m1.pounds=25000;
cout<<m1.rice<<endl;
cout<<m1.car<<endl;
cout<<m1.pounds<<endl;
return 0;
}