Pointers as address variables - C++ Data Type

C++ examples for Data Type:Pointer

Description

Pointers as address variables

Demo Code

#include <iostream>
using namespace std;
int main()//  w  ww.j  av a2  s .com
{
   int var1 = 11;
   int var2 = 22;
   cout << &var1 << endl      //print addresses of variables
        << &var2 << endl << endl;
   int* ptr;                  //pointer to integers
   ptr = &var1;               //pointer points to var1
   cout << ptr << endl;       //print pointer value
   ptr = &var2;               //pointer points to var2
   cout << ptr << endl;       //print pointer value
   return 0;
}

Result


Related Tutorials