Using Pointers to Point to Something Else and Back Again - C++ Data Type

C++ examples for Data Type:Pointer

Description

Using Pointers to Point to Something Else and Back Again

Demo Code

#include <iostream> 

using namespace std; 

int main() /* www .j  a  v  a2  s . com*/
{ 
  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; 
}

Result


Related Tutorials