I understand all of this example code.Code:#include <iostream> using namespace std; int main() { int x; // I understand this is an integer and it's named x. int *p; // I understand this is a pointer to an integer. p = &x; // I understand this read p and "assign the address of x to p". cin>> x; // I understand this put a value in x, we could also use *p here. cin.ignore(); cout<< *p <<"\n"; // I understand this outputs the value of "p which is equal to x". cin.get(); }
What I don't understand is why they are used. Couldn't one just use a variable?
I've viewed the tutorials on 'pointers' numerous times and visited multiple other sites that explained it, but I'm still confused.
Does anyone know anywhere I can get a better explanation of what a pointer is and why they're used?