Hi ! I am currently learning C++, I am now experimenting with Pointers.
now I created a very tiny program that says the memory address of x
now I noticed that every time I run the program the result is different.
so my question is this : Does memory address of a variable changes every time the program run ?
Yes, of course, the memory location of a variable can change. This is because the operation system has to manage the memory locations carefully, since the OS has to manage many applications and choose the best location to place something rather something else.
They change ,you don't have to care about them and that's one of the best things with using Higher Level Languages , you don't have to care about memory addresses , they may be different each time you run it.
This is because the operation system has to manage the memory locations carefully, since the OS has to manage many applications and choose the best location to place something rather something else.
In all modern OSs the address space of each program is independent ranging 0(un-addressable by default),1 ... 2processor_word_size-1 , in most cases.
It has nothing to do with the physical address each byte co-relates to , it might even change during run time (swap etc.).