-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.cpp
More file actions
21 lines (19 loc) · 779 Bytes
/
struct.cpp
File metadata and controls
21 lines (19 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// In C++, classes and structs are blueprints that are used to create the instance of a class.
// Structs are used for lightweight objects such as Rectangle, color, Point, etc.
// Unlike class, structs in C++ are value type than reference type.
// It is useful if you have data that is not intended to be modified after creation of struct.
// C++ Structure is a collection of different data types.
// It is similar to the class that holds different types of data.
#include <iostream>
using namespace std;
struct Rectangle
{
int width, height;
};
int main(void) {
struct Rectangle rec;
rec.width=8;
rec.height=5;
cout<<"Area of Rectangle is: "<<(rec.width * rec.height)<<endl;
return 0;
}