-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointersToPointers.cpp
More file actions
63 lines (48 loc) · 1007 Bytes
/
PointersToPointers.cpp
File metadata and controls
63 lines (48 loc) · 1007 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <array>
using namespace std;
int *ptArray(int *p, int size){
int *q;
q=p;
for(int i=0; i <size;i++){
*p = i;
cout << *p << endl;
p++;
}
cout << p << endl;
return q;
}
int globalV = 42;
void changePointerValue( int** ptr_ptr){
*ptr_ptr = &globalV;
}
int main(){
int var = 23;
int *pointer2var = &var;
cout << "Value before passing: " << *pointer2var << endl;
changePointerValue(&pointer2var);
cout << "AFter: " << *pointer2var << endl;
return 0;
int SIZE = 9;
int *p, *q;
p = new int[SIZE];
q = p;
cout << p << endl;
for(int i=0; i <SIZE;i++){
*p = i;
cout << *p << endl;
p++;
}
p = q;
cout << p << endl;
//returns address of pointer to p
p = ptArray(p, SIZE);
cout << p << endl;
p = q;
//address OF pointers: ----------------EXTRA---------------
cout << &p << endl;
cout << &q << endl;
cout << *(p+5) << endl; //prints 5, the 5th element
}