Pointers

This is a discussion on Pointers within the C++ Programming forums, part of the General Programming Boards category; Hello, me agian I was wondering if you can have a variable, address it to two dif pointers, and have ...

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    Pointers

    Hello, me agian

    I was wondering if you can have a variable, address it to two dif pointers, and have a dif number. like for example:



    .....
    int main()
    {
    int x;
    //address x to two pointers
    cin>>x;
    //put this value into the x thats in one pointer
    cin>>x;
    //put this calue into the x thats in the other pointer
    return 0;
    }




    Does that seem possible?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    a pointer is just a variable that contains a memory address... it can only point to/contain one address at a time. you can have 2 pointers pointing to the one item, but there's still only one item!

    int x = 10;
    int* px1 = &x;
    int* px2 = &x;

    *px1 will always be the same as *px2....

    you can write to x using both px1 and px2, but they are both being written to x, and therefore it's only ONE item that's being changed.

    you can do this:

    int x, y;

    int* p = &x;
    cin >> *p;
    p = &y;
    cin >> *p;

    and this changes 2 different things with the one pointer.

    i hope this helps, it was quite a hard question to answer because the question didn't really make any sense!!

    good luck
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 06:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 11:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM

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