Using int pointers : int pointer « Data Types « C++ Tutorial






#include <iostream>
 using std::cout; // this file uses std::cout
 
 int main()
 {
     int intValue;         // a variable
     int * intPointer = 0;    // a pointer
 
     intValue = 5;
     intPointer = &intValue;     // assign address of intValue to intPointer
     cout << "intValue: " << intValue << "\n";
     cout << "*intPointer: " << *intPointer << "\n\n";
 
     cout << "*intPointer = 7\n";
     *intPointer = 7;         // sets intValue to 7
     cout << "*intPointer: " << *intPointer << "\n";
     cout << "intValue: " << intValue << "\n\n";
 
     cout << "intValue = 9\n";
     intValue = 9;
     cout << "intValue: " << intValue << "\n";
     cout << "*intPointer: " << *intPointer << "\n";
 
     return 0;
 }
intValue: 5
*intPointer: 5

*intPointer = 7
*intPointer: 7
intValue: 7

intValue = 9
intValue: 9
*intPointer: 9








2.3.int pointer
2.3.1.Using int pointers
2.3.2.Get address of an int variable
2.3.3.Calculation based on pointer