Adress of a pointer.

This is a discussion on Adress of a pointer. within the C Programming forums, part of the General Programming Boards category; I am trying to assign adress of a pointer to a pointer. so far: Code: #include <stdio.h> #include <string.h> int ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    151

    Adress of a pointer.

    I am trying to assign adress of a pointer to a pointer.

    so far:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    
    int main()
    {
    	int *ptr;
    	int y;
    	int **ptr2;
    	ptr=&y;
    	ptr2=&ptr;
    	printf("%p   %p",ptr,ptr2);
    	return 0;
    
    
    
    
    }
    So According to what I think , every pointer has also an adress of their own which has the information about the adress that pointer points. Am I true?

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,660
    You're right.

    A pointer is a variable that contains a memory address as its value, just like ints have an integer as a value. And since pointers take up small parts of memory like other types of variables, information about the pointer itself is stored at an address that is very different from its value. So if that made sense, then yeah, pointers can have the location of other pointers as values.

    But the thing is, no variable is aware of its own address. Hence, C has an operator that will fetch it for you.

    Dereferencing T *p is something different. It's another operator that returns the T stored in its value.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    151
    Thanks perfect gentleman =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 01:36 AM
  2. Pointer (adress) question.
    By omnificient in forum C Programming
    Replies: 22
    Last Post: 02-27-2008, 07:49 AM
  3. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 07:23 PM
  4. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 08:40 PM
  5. want to assign myself the adress of a pointer
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 07-22-2002, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21