Struct in C++, source code

Yesterday I had the question about “How to use struct in C++” then I found the answer not too hard. Because I was pass it before.
Look at the example code below and see the description in the comment.

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
#include <iostream>
using namespace std;
 
// struct name MyStruct
struct MyStruct{
	int num1;
	int num2;
};
 
// return type is MyStruct
// 1 parameter is MyStruct
// +5 in every attributes of this object
MyStruct plus5(MyStruct mNode){
	mNode.num1 += 5;
	mNode.num2 += 5;
	return mNode;
}
 
void main(){
	MyStruct m1;
	m1.num1 = 5;
	m1.num2 = 7;
 
	MyStruct m2 = plus5(m1); // object m2 is the m1 after +5 both num1 and num2
 
	cout << m2.num1 << endl;
	system("pause"); // stop process to see the result
}

This is the basic struct in C++ and how to use struct with return value.