-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreferences.cpp
More file actions
30 lines (22 loc) · 772 Bytes
/
references.cpp
File metadata and controls
30 lines (22 loc) · 772 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
#include <iostream>
using namespace std;
int main()
{
// Diff between pointer and ref.
// 1. You cannot have NULL references.
// You must always be able to assume that a reference
// is connected to a legitimate piece of storage.
// 2. Once a reference is initialized to an object,
// it cannot be changed to refer to another object.
// Pointers can be pointed to another object at any time.
// 3. A reference must be initialized when it is created.
// Pointers can be initialized at any time.return 1;
int i = 51;
// int &r; // error
int &r = i;
cout << "Value: " << i << endl;
cout << "Address: " << &i << endl;
cout << endl;
cout << "Value: " << r << endl;
cout << "Address: " << &r << endl;
}