contrasting pointers from non-pointers
Hi All,
This is a general elementary level C question, but somehow i am stuckup at its logical understanding. hopefully i can get good know-how on it from the forum.
My question is that if we say that a pointer type variable is a variable whose address is known to us somehow. So we access that variable by using its address that is saved at some other location in the memory.
Now assuming that my above understanding is correct for a pointer type variable, then i want to know how would we access some variable which is just a simple int type or long type etc... and we dont know its addess in the memory?
Any help would be great.
-naim1
Re: contrasting pointers from non-pointers
You missed one level of indirection. A pointer is a variable which stores one address, it´s not the address itself. So using the pointer´s "value" means accessing a specific memory location.
Each variable, no matter what type, has its own address where it resides in memory.
Re: contrasting pointers from non-pointers
Thanks for the reply. I think it makes sense now... little ilttle.
BTW, does a simple C compiler makes any address lookup table while compiling a program to keep track of the variables while execution , or some way other ...
Re: contrasting pointers from non-pointers
The compiler maintains a lookup table like that while compiling but that table is discarded when the compiler finishes. When the program executes it has the addresses hard-coded inline in the machine code.