-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut14.cpp
67 lines (52 loc) · 1.19 KB
/
tut14.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;
// struct Book
// {
// int pages;
// float cost;
// string author;
// };
typedef struct Book
{
int pages;
float cost;
string author;
} bk;
// UNION: similar to struct but with better memory management
union money
{
// you can use only one of the given data. Hence memory is shared.
int rupee;
float pounds;
char country;
};
int main()
{
// STRUCTURES, UNIONS and ENUMS
// Structures: unlike arrays, used to store multiple types of data types.
// struct Book HarryPotter;
bk HarryPotter;
HarryPotter.author = "jk rowling";
HarryPotter.cost = 35.5;
cout << HarryPotter.author << endl;
cout << HarryPotter.cost << endl;
union money m;
m.rupee = 100;
cout << m.rupee << endl;
m.pounds = 34.4;
cout << m.pounds << endl;
cout << "Garbage value of rupee will be printed as value to pounds has been assigned: " << m.rupee << endl;
// ENUM: given integer value
enum Meal
{
breakfast,
lunch,
dinner
};
cout << breakfast << endl;
cout << lunch << endl;
cout << dinner << endl;
Meal m1 = lunch;
cout << m1;
return 0;
}