-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
31 lines (22 loc) · 898 Bytes
/
main.cpp
File metadata and controls
31 lines (22 loc) · 898 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
#include <iostream>
using namespace std;
int main() {
// Declare a variable for holding an address,
// which are of a standard length.
// Sometimes initializing a pointer to 'nullptr' is good to do.
int* int_ptr = nullptr;
//Setting the value of i to 39.
int i = 39;
//Setting up a 2nd reference to the integer i.
int &int_ref = i;
// [*] Set the int_ptr to have the address of the variable i.
int_ptr = &i;
//Pinting to the console the de-referenced value at the address held by int_ptr.
cout << *int_ptr << endl;
//[**] Changing the value of int_ptr to now have the address of int_ref which happens to be the same
// Address as i.
// Compare [*] and [**].
int_ptr = &int_ref;
// Consequently the value obtained by de-referencing the contents of that same address is the same value, 39.
cout << *int_ptr << endl;
}