I write a C program gets in an environment variable's name and print out it's memory address, simply use the getenv(
) function to do the job. Let's say I wanna have the address location of PATH --> ./test PATH. But when I debug that program in gdb, the memory location of that variable is different. Can you explain in detail why is there such a different?
To be more exact:
./test PATH
--> 0xbffffd96
debug in gdb --> 0xbffffd53
[edit] Thanks for your explanations. What I actually in question about is, how the memory address of a variable (in this case, an environment variable) changes with different programs. For example, I have 2 program a.out and b.out
./a.out
--> PATH's address is some number
./b.out
--> another number
So, what causes this difference between 2 numbers? I hope I have clearly demonstrated what I want to ask. Thanks mates.