-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublePointers.cpp
More file actions
41 lines (34 loc) · 972 Bytes
/
doublePointers.cpp
File metadata and controls
41 lines (34 loc) · 972 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
40
41
#include <iostream>
using namespace std;
void update(int **p){
// p = p + 1;
// *p = *p + 1;
**p = **p + 1;
}
int main(int argc, char const *argv[])
{
int a = 5;
int *ptr = &a;
int **ptr2 = &ptr;
/* cout << "val of a " << a << endl;
cout << "add of a " << &a << endl;
cout << "add of a " << ptr << endl;
cout << "val of a " << *ptr << endl;
cout << "val of ptr " << ptr << endl;
cout << "add of ptr " << &ptr << endl;
cout << "add of ptr " << ptr2<< endl;
cout << "val of ptr " << *ptr2 << endl;
cout << "val of a " << **ptr2 << endl;
cout << "val of ptr2 " << ptr2 << endl;
cout << "add of ptr2 " << &ptr2 << endl;
*/
cout << endl;
cout << "Before " << a << endl;
cout << "Before " << ptr << endl;
cout << "Before " << ptr2 << endl;
update(ptr2);
cout << "After " << a << endl;
cout << "After " << ptr << endl;
cout << "After " << ptr2 << endl;
return 0;
}