+ 2

Why is the memory adress of my variable always the same? Can somebody explain me please?

Hello. I was writing a very simple program to learn working with pointers and I found an intresting fact: When it output memory adress of my variable, it is alway the same value. The program looked like this: int Age = 16; int *AgePtr = &Age; cout << AgePtr; It always output value 0x28ff18. I am new in programming comunity and I don't know how exactly computer memory works, but I thought, that it will save the variable into first free space in memory that it finds. It outputs 0x28ff18 even after restarting.

21st Feb 2018, 9:13 PM
Jan Štěch
Jan Štěch - avatar
3 Réponses
+ 7
http://www-bcf.usc.edu/~dkempe/CS104/08-29.pdf ^Read through that document. It'll help educate you further on how memory works. Hope that helps your understanding.
21st Feb 2018, 9:35 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
Thank you ^v^
21st Feb 2018, 9:37 PM
Jan Štěch
Jan Štěch - avatar
+ 2
You're more than welcome! Best of luck to you in your learning.
21st Feb 2018, 9:42 PM
Fata1 Err0r
Fata1 Err0r - avatar