Accessing the variable pointed to - C++ Data Type

C++ examples for Data Type:Pointer

Description

Accessing the variable pointed to

Demo Code

#include <iostream>
using namespace std;
int main()/*from www. j a  v a  2 s .  c  o m*/
{
   int var1 = 11;             //two integer variables
   int var2 = 22;
   int* ptr;                  //pointer to integers
   ptr = &var1;               //pointer points to var1
   cout << *ptr << endl;      //print contents of pointer (11)
   ptr = &var2;               //pointer points to var2
   cout << *ptr << endl;      //print contents of pointer (22)
   return 0;
}

Result


Related Tutorials