While looking over some examples on this site I realized I didn't understand pointers. Well, I took the example code and decided to play with that some to see if I could better understand them, when to use them or why.
Here is the original code
Well, I decided to see what kind of answers I would get if there were no pointers in this code in order to solve the why question I had for these tricky guys. Here is where the interesting part comes in. As long as I enter a number(thats not too large) I will get the answer 2 when all pointers are removed(3 if your counting). I couldn't seem to figure out why. Hopefully someone here will be able to tell me why...and perhaps give me a good definition of when and why to use pointers. I think I understand...but I am sure hearing a few different definitions will help out a lot.Code:#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int x; int *p; p = &x; cin>> x; cin.ignore(); cout<<*p <<"\n"; cin.get(); }