-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pointer.cpp
67 lines (47 loc) · 1.37 KB
/
Pointer.cpp
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
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
void update(int *a,int *b) {
*a=*a + *b;
*b=abs(*a - 2* *b); // Complete this function 2**b means 2 multiply pointer b bcoz b value increased after above summation
}
int main()
{
int t=9; int*a;
*a=t; *a=8;
cout<<endl<<*a;
int a, b;
int* pa = &a, *pb = &b;
scanf("%d %d", &a, &b);
update(pa, pb);
printf("%d\n%d", *pa, *pb);
printf("%d\n%d", // can a pointer stores pointer itself or can a pointer stores integer or character
int a =10;
int *ap1 = &a;
int **ap2 = &ap1;
int ***ap3 = &ap2;
int s =10;
int *e = &s ;
int * r = e;
cout<<*e<<endl<<e<<endl<<r<<endl<<&e;
**ap3 = &a;
*ap3=ap2;
**ap3 = &a;
int ****aptr4 = &aptr3;
cout<<****aptr4;
cout<<aptr4<<endl<<&aptr3
i can do
aptr = &a;
aptr = aptr;
*aptr = 12;
// // but i cannot do (error codes)
&aptr = &a; // addresses are immutable and hard coded
*aptr = aptr; // this was only possible if *aptr was pointer of another pointer
// means
// int a =10;
// int *first = &a;
// int *pointer_to_first_pointer = &first;
// *pointer_to_first_pointer = first; ---> this means now pointer to first pointer stores address of a not of first pointer
aptr = &aptr; // pointer cannot store address of itself
cout<<aptr<<endl<<&aptr;
return 0;
}