Pointer Basics
#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
/* A pointer is a variable that holds a memory address, usually the location of another variable in memory. */
int main()
{
int *ptr; // Defining a pointer.
int i=100;
ptr=&i; // Memory address of i is obtained by the reference operator '&' and it is assigned to pointer ptr.
cout << "Memory Address: "<< ptr << endl; // Prints the memory address of i which is hold by pointer ptr.
cout << "Value contained in the address: "<< *ptr; // Prints the value hold by the variable i.
return 0;
}
Output:
Memory Address: 0032FC58
Value contained in the address: 100