-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBai37.cpp
More file actions
39 lines (30 loc) · 709 Bytes
/
Bai37.cpp
File metadata and controls
39 lines (30 loc) · 709 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
/*
Con trỏ và tham chiếu
*/
#include <iostream>
using namespace std;
void changeNumber(int n) {
n = 2 * n;
}
void changeNumber2(int* n) {
*n = *n * 2;
}
void changeNumber3(int& n) {
n = n * 2;
}
void changeNumber3(const int& n) {
//n = n * 2;
}
int main() {
int n = 100;
cout << "Truoc khi goi ham changeNumber: " << n << endl;
changeNumber(n);
cout << "Sau khi goi ham changeNumber: " << n << endl;
cout << "Truoc khi goi ham changeNumber2: " << n << endl;
changeNumber2(&n);
cout << "Sau khi goi ham changeNumber2: " << n << endl;
cout << "Truoc khi goi ham changeNumber3: " << n << endl;
changeNumber3(n);
cout << "Sau khi goi ham changeNumber3: " << n << endl;
return 0;
}