Pointers, please check?

Can someone check if I got these correct please?? I'm pretty sure I missed almost half of these so I really need help on these. If someone can explain too, that would be really nice.

a: 5
b: address of location of x (0x....)
c: address of value x (0x...)
d: address of value x (0x...)
e: 5
f: 3
g: 3
h: 6
i: 9
j: vals
k: address of vals + 1
l: address of ptrVals + 2
m: 0
n: 55
o: 55
p: 0


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
int x;
int *ptrX;
  
x = 5;
  
ptrX = &x;
  
  
cout << "a:" << x << endl;
cout << "b:" << &x << endl;   
cout << "c:" << ptrX << endl;
cout << "d:" << &ptrX << endl;
cout << "e:" << *ptrX << endl;
  
int vals[3];
  
*vals = 3;
  
vals[1] = *vals + 3;
  
*(vals+2) = 9;
  
cout << "f:" << vals << endl;
cout << "g:" << vals[0] << endl;
cout << "h:" << vals[1] << endl;
cout << "i:" << vals[2] << endl;

  
int *ptrVals;
  
ptrVals = vals;
  
cout << "j:" << ptrVals[0] << endl;
  
cout << "k:" << *(vals+1) << endl;
  
cout << "l:" << *(ptrVals+2) << endl;
  
int *ptr = NULL;
  
cout << "m:" << ptr << endl;
  
const int intRate = 55;   
const int *ptrRate;
ptrRate = &intRate;
  
cout << "n:" << intRate << endl;
  
*ptrRate = 66;
  
cout << "o:" << intRate << endl;
int * const ptrY = &x;
  
ptrY = &vals[0];
cout << "p:" << *ptrY << endl;
const int * const ptrZ = &intRate;
  
ptrZ = &vals[0];
  
*ptrZ = 7;
Last edited on
Topic archived. No new replies allowed.