WEB DEVELOPER SITE
PYTHONPHPJAVA
 

C++ Pointers


Every variable is a memory location, which has its address defined.

This outputs the memory address, which stores the variable score.
    int score = 6;
    cout << &score << endl;
The only difference between pointers of different data types is the data type of the variable that the pointer points to. A pointer is a variable, and like any other variable, it must be declared before you can work with it. The asterisk sign is used to declare a pointer
int *ip;  // pointer to an integer
double *dp;   // pointer to a double
float *fp;  // pointer to a float
char *ch;  // pointer to a character



How to use Pointers

scorePtr's value is the memory location of score.

    int score = 12;
    int *scorePtr;
    scorePtr = &score;

    cout << scorePtr << endl;
//Outputs "0x23fe44
"