I have wondered about ordinary code. Assume we are running this code on any modern System like Unix/Linux/Mac/Windows. This code is C, but it should work with every language which is close to the hardware.
int a = 8; //printf("%d", (int)&a);
This will show obviously that the system allocated the int dynamically. So there is no static address used. Now we continue by:
a = a+1;
Now, my question follows:
Since the address to "a" is allocated dynamically, we need presumably a pointer which points to a pointer pointing to "a". But how do we store this pointer? We would again need a dynamically allocated address and would, therefore, pass the problem. So, in my mind, we need static addresses the program can use, but how does the process know these addresses?
How does the process store its own allocations, so that after initializing a variable, the process knows what the variable actually is or at least where the variable was allocated?
If this question is not clear enough, please comment below.