C++ Pointer Point to Something Else and Back Again

Description

C++ Pointer Point to Something Else and Back Again

#include <iostream> 

using namespace std; 

int main() /*  www .j  a  va  2  s.c  o  m*/
{ 
  int i; 
  int j; 
  int *ptrToComp; 

  ptrToComp = &i; 
  
  *ptrToComp = 2; 
  
  cout << *ptrToComp << endl; 

  ptrToComp = &j; 
  
  *ptrToComp = 5; 
  
  cout << *ptrToComp << endl; 

  ptrToComp = &i; 
  
  cout << *ptrToComp << endl; 
  
  return 0; 
}



PreviousNext

Related