-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathStructurepointer.cpp
116 lines (48 loc) · 1.06 KB
/
Structurepointer.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// C++ program to illustrate the
// structure pointer
#include <iostream>
#include <stdio.h>
using namespace std;
// Structure declaration for
// vertices
struct point {
int x;
int y;
};
// Structure declaration for
// rectangle
struct rect {
// An object left is declared
// with 'point'
struct point left;
// An object right is declared
// with 'point'
struct point right;
};
// Function to calculate area of
// the given rectangle
void areaOfRectangle(struct rect r)
{
// Find the area of the rectangle
// using variables of point
// structure where variables of
// point structure is accessed
// by left and right objects
int area
= (r.right.x - r.left.x)
* (r.right.y - r.left.y);
// Print the area
cout << area;
}
// Driver Code
int main()
{
// Initialize variable 'r'
// with vertices of rectangle
struct rect r = { { 0, 0 }, { 1, 1 } };
// Function Call
areaOfRectangle(r);
return 0;
}
Output:
1