different output depending on scopes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

different output depending on scopes

code below shows how if use assign a ref and then change the value w ptr in different scope, ref continues w the old value. Instead if do it at same scope, no. why? its cause the aux reference? thx https://code.sololearn.com/c77bC48EU746/?ref=app

14th Aug 2019, 4:42 PM
BinaryEden
BinaryEden - avatar
3 Answers
+ 4
"ref = n" == ref=100; If you try cout<<aux it gives 100 too, ref refers aux always.. e.g.: the first assignment of ref is the initialization of ref => address of aux, the 2nd assignment is a normal value assignment. There is a something wrong about ptr in "TEST=true" scope here instead, the variable it points no longer exists after "if(true)" block.. Here there's why.. https://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope
14th Aug 2019, 5:08 PM
AZTECCO
AZTECCO - avatar
+ 3
Thank you! Good job btw.. your approach will make you a strong programmer 👍
15th Aug 2019, 7:28 AM
AZTECCO
AZTECCO - avatar
+ 1
haha AZTECCO good answers as ever
14th Aug 2019, 11:12 PM
BinaryEden
BinaryEden - avatar