Thread: Making and Using A Pointer

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Making and Using A Pointer

    How would I create a simple pointer and use it? An example would be cool, too. Please don't redirect me to another website.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Compile this and watch the result
    Code:
    int MyVariable;
    int* MyPointer;
    
    Myvariable = 5;
    MyPointer = &MyVariable; //make the pointer pooint to MyVariable
    
    cout << "MyPointer: " << MyPointer << endl; //Print the value of the pointer (the adress)
    cout << "*MyPointer: " << *MyPointer << endl;//Print the value of what the pointer points at
    cout << "MyPointer[0]: " << MyPointer[0] << endl;//Print the first element of what the pointer points at (pointers are like arrays). This is usually the same as *MyPointer
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Exclamation Thank You

    Thank You, That Was Exactly What I Needed.

Popular pages Recent additions subscribe to a feed