CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    317

    Cool 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
    Last edited by naim1; January 27th, 2011 at 09:14 PM.

  2. #2
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    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.
    - Guido

  3. #3
    Join Date
    Jan 2005
    Posts
    317

    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 ...

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    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.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured