I am writing a C program that gets the name of an environment variable and prints its memory address, just use the function getenv() to complete the job. Say I want to have the address location PATH → ./test PATH. But when I debug this program in gdb, the memory location of this variable is different. Can you explain in detail why there is such a different?
More precisely:
./test PATH → 0xbffffd96
debug in gdb -> 0xbffffd53
[edit] Thanks for your explanation. I actually doubt how the memory address of a variable (in this case, an environment variable) changes with different programs. For example, I have 2 programs a.out and b.out
./a.out → The PATH address is a number
./b.out → another number
So what causes this difference between the two digits? Hope I have clearly demonstrated what I want to ask. Thank you comrades.
source
share