+ 6
Unexpected output c++ pointers
Why the output is such ? https://www.sololearn.com/post/108346/?ref=app In sololearn lesson, output is something else https://www.sololearn.com/learn/CPlusPlus/1630/
10 Respuestas
+ 2
It just depends from compiler to compiler and pc to pc I guess.
They may be the same number to you, but the actual address may be completely different due to https://en.wikipedia.org/wiki/Virtual_address_space
gcc on my pc ( and sololearn too appearently ) always seems to give me the same address too, but vc++ gives me a different one each time.
You can try your code here:
https://rextester.com/l/cpp_online_compiler_visual
This one does give a different address each time.
+ 5
Anna
I get same result each time in both SL editor and My PC
+ 4
Anna
I am 100% sure
+ 4
@~swim~
Sorry, I can't directly tag you, as I am using PC now.
I properly recompiled my code using key: F9
It rebuilded the binary file and ran my code. I am sure, the problem is not that.
I guess, the output is such due to my PC || My Compiler.
@Dennis
The web compiler you shared link, I ran code in it. It gave me different results each time I ran.
I finally understood why this happens. The whole game is of memory.
+ 3
The & operator returns the memory address where the variable is stored. If you run the code multiple times on your pc, you'll get a different value each time.
+ 2
SPACE That's interesting, are you sure? 🤔 The addresses on your pc might look very similar, but they should be different each time
+ 2
Dennis I noticed him using GCC and I get different addresses each time with GCC and Ubuntu 😁
I didn't know that this might be dependent on the pc or compiler. Learning never stops I guess
+ 1
Because you are printing address of scores not the value of scores