+ 1
Int x=5; int *p=&x; here the below two lines get same answer . x=*p+4(x= 4+4); *p=*p+4(4=4+4). How it is the correct.
*p results value at that address. Is it think value 4 or x in place of*p in left side of assainment operator in last statement
4 odpowiedzi
+ 1
Could you explain dereferencing concept
+ 1
p stores the address of x
*p is called dereferencing, since it gives the value stored at that address (in this case x)
So basically x and *p are the same.
imagine it in memory like this:
|.0.|.1.|.2|.3.|.4.|.5.|6.|
|....|.x.|....|....|.p.|....|....|
|....|.4.|....|....|.1.|....|....|
first row is the address
second the variable names
third the value
&x gives the address of x (here 1, thats why p has value 1)
*p checks which value is located in the address it points to (p points to address 1 and there is value 4 in it).
Hope it is more clear now 🙈