Just now starting on pointers , and I has questionz.
Code:
#include <iostream>
using namespace std;
int main()
{
int x; // A normal integer
int *p; // A pointer to an integer
p = &x; // Read it, "assign the address of x to p"
cin>> x; // Put a value in x, we could also use *p here
cin.ignore();
cout<< *p <<"\n"; // Note the use of the * to get the value
cin.get();
}
Ok, I understand in the beginning int *p is declaring the pointer p, and the statement after that p = &x, is stating that the variable, not the pointer, p is holding the address for the variable x. Then when the cout statement comes up, it is outputting the value of x by checking the address to see what is stored there.....correct? I probably made that alot more difficult than it should've been.