-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreferenceData.cpp
More file actions
28 lines (20 loc) · 873 Bytes
/
referenceData.cpp
File metadata and controls
28 lines (20 loc) · 873 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
#include <iostream>
int main() {
int num;
//reference provide access to the value of a variable
//reference can be used to change the value of a variable with appropriate type
//"&" is reference operator
//reference is an alias for the item associated in its declaration
//reference=type of the variable with "&" along with the variable name and "r"
//reference will always refer to the item which it was initialized with
int& rNum = num;
rNum = 400;
std::cout << "Value direct: " << num << std::endl;
std::cout << "Value reference: " << rNum << std::endl;
std::cout << "Address direct: " << &num << std::endl;
std::cout << "Address reference: " << &rNum << std::endl;
rNum *= 2;
std::cout << "Value direct: " << num << std::endl;
std::cout << "Value reference: " << rNum << std::endl;
return 0;
}