+ 3

if *p indicates the value then what does **p or ***p indicate?? Many question in challenges also contain *&p and *p*

18th May 2017, 4:50 AM
U L Knw Me soon😉😋
U L Knw Me soon😉😋 - avatar
3 ответов
+ 2
First of all, you should understand how pointers work. A pointer is a variable whose value is the address memory of another variable –that is, it's position in the computer memory. Take, for example, this case: variable i, value 23, address 0x000001 variable *p, value 0x000001, address 0x000002 Now i == 23, p == 0x000001 (this is easy). The crucial fact here is that *p == 23, because *p means "take the value of p, interpret it as a memory address, and fetch the value of that address". So it is said that *p "points to" i. The other way around, &p stands for the memory address of p, rather than its value. So &i == 0x000001 and &p == 0x000002.
18th May 2017, 5:27 AM
Álvaro
+ 2
int a=0; a is a int value int *p; p is a pointer (a variable that can contains a int variable adress) so you can write it : p = &a; because &var return the adress of var. Now : *p will return the value of a and &p the adress of p. If you want to store the adress of the p variable, you have to create a pointer for int pointers like this : int ** p2 = &p; so &p2 return the adress of p2. And *p2 return p so **p2 return *p = a. Note that the * can also be used for multiplication. You can for example have this : int b = **p2 * *p * a * **p2; = a * a * a * a;
18th May 2017, 5:28 AM
Glozi30
Glozi30 - avatar