Tell me exactly what is the point you don't understand?
A pointer is the memory address a value is stored in (and the amount of bytes it stores with that data type). Creating an int pointer (a pointer that can point to integers) is done like so: int* pointername; Unlike references, pointers can be given other objects to point to during runtime. Some more advanced aspects which you need not look at for the time being: Pointers can also be used to store arrays in a more flexible way and are also used for dynamic memory allocation.
#include <iostream>
int main()
{
int Variable; // Create a new variable to store a value in
std::cin >> Variable; // Input an integer and store it in Variable
int* Pointer; // Create a pointer to an integer
Pointer = &Variable; // Store the ADDRESS of Variable in it. (&Variable)
std::cout << "Variable:" << Variable << std::endl; // Show the value of Variable
std::cout << "Pointer:" << Pointer << std::endl; // Show the address store in Pointer
std::cout << "*Pointer:" << *Pointer << std::endl; // Show the value that the address in Pointer points to (is equal to Variable)
std::cout << "&Variable:" << &Variable << std::endl; // Show the address that the value of Variable is store in (is equal to Pointer)
system("pause"); // Pause the console window
return 0;
}
//THIS GOES IN MAIN
int MyInt = 0;
int set = 0;
std::cout << "MyInt: " << MyInt << "\nSet to: ";
std::cin >> set;
setInt(&MyInt,set);
std::cout << "\nstd::cin >> set;\nsetInt(" >> &MyInt >>"," >> set >> ");";
std::cout << "\nMyInt: " << MyInt;
system("pause"); //EDIT: PAUSE!
//THIS IS A FUNCTION OUTSIDE OF MAIN
//setInt(&var,NUMBER);
void setInt(int *out, int in) {
*out = in;
}
//setInt(&var,&variable or pointer);
void setInt_p(int *out, int *in) {
*out = *in;
}
/*
OUTPUT:
MyInt: 0
Set to: 8 OR WHATEVER
std::cin >> set;
setInt([ADDRESS],8);
MyInt: 8
Press any key to continue...
*/