How do computers store variable addresses?

14 views Asked by At

In a nutshell, variables are just addresses pointing to a memory location by which when the variable is called on, it points to that address.

But then I was wondering, since the address for these variables are unique, and are strings and numbers themselves, how does the computer store that?

And how does it know that THAT unique address is to be for that variable? As me (the developer), can have multiple programs with the same variable name but have different values for each, therefore the memory allocated to that variable has to be addressed in some other way then the name itself. So how does it work?

How is a example:

This is program A, containing the variable x:

x = 10

This is program B, also containing the variable x:

x = 15

Now, if I call x in program A, the value 10 is returned.

But if I do it in program B, the value 15 is returned.

How does that work? What is used to address the variables although they have the same name? Doesn't the address to the variable's value need to also be stored somehow? And how does the address know what value to point at even if I run the programs at the same time?

0

There are 0 answers