How would I create a simple pointer and use it? An example would be cool, too. Please don't redirect me to another website.
This is a discussion on Making and Using A Pointer within the C++ Programming forums, part of the General Programming Boards category; How would I create a simple pointer and use it? An example would be cool, too. Please don't redirect me ...
How would I create a simple pointer and use it? An example would be cool, too. Please don't redirect me to another website.
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.
Thank You, That Was Exactly What I Needed.