0
PLEASE HELP - Can someone please explain the output of this code?
https://code.sololearn.com/cRCcXLp8Y76s/?ref=app The output of this code is 1021. Can someone please explain why? Please be specific and go through all steps of the code. NOTE: I didnât write this code. Credit goes to Naveen Kumar
5 Answers
+ 3
you create ptr as pointer to x
when you do ptr++ the pointer moves one place in memory and it points somewhere ...
so x remains 10
you create ref as reference to y
that means it behaves as if it was one variable
changes in ref are done in y
so y is incremented and it is 21
+ 3
yes, you only move the pointer away
if you did
(*ptr)++;
it would increase x, because *ptr is the value
ptr is a memory address
+ 1
So when it says ptr++ it doesnât increase because changing pointer doesnât affect the x?
+ 1
Thanks a lot Michal!
0
@michal can you please go to this link?
https://www.sololearn.com/Discuss/1232575/please-explain-the-output-of-this-code
It's another question that I have. Thanks!