C++ Pointer Accessing the variable pointed to

Description

C++ Pointer Accessing the variable pointed to

#include <iostream>
using namespace std;
int main()//  www  .j av  a 2s  . com
{
   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;
}



PreviousNext

Related