What is stored in a pointer. : pointer « Pointer « C++ Tutorial






#include <iostream>
 
 int main()
 {
     unsigned short int intValue = 5, yourAge = 10;
     unsigned short int * intPointer = &intValue;  // a pointer
 
     std::cout << "intValue:\t" << intValue;
     std::cout << "\t\tyourAge:\t" << yourAge << "\n";
     std::cout << "&intValue:\t" << &intValue;
     std::cout << "\t&yourAge:\t" << &yourAge <<"\n";
 
     std::cout << "intPointer:\t" << intPointer << "\n";
     std::cout << "*intPointer:\t" << *intPointer << "\n\n";
 
     intPointer = &yourAge;       // reassign the pointer
 
     std::cout << "intValue:\t" << intValue;
     std::cout << "\t\tyourAge:\t" << yourAge << "\n";
     std::cout << "&intValue:\t" << &intValue;
     std::cout << "\t&yourAge:\t" << &yourAge <<"\n";
 
     std::cout << "intPointer:\t" << intPointer << "\n";
     std::cout << "*intPointer:\t" << *intPointer << "\n\n";
 
     std::cout << "&intPointer:\t" << &intPointer << "\n";
     return 0;
 }
intValue:       5               yourAge:        10
&intValue:      0x22ff76        &yourAge:       0x22ff74
intPointer:     0x22ff76
*intPointer:    5

intValue:       5               yourAge:        10
&intValue:      0x22ff76        &yourAge:       0x22ff74
intPointer:     0x22ff74
*intPointer:    10

&intPointer:    0x22ff70








11.1.pointer
11.1.1.What is stored in a pointer.
11.1.2.Allocating and deleting a pointer
11.1.3.Finding Out What Is Stored in Pointers
11.1.4.Manipulating Data by Using Pointers
11.1.5.Using a pointer to print the contents of the array
11.1.6.C++ program shows the use of pointers when accessing structure information from a function.
11.1.7.Pointers to Derived Types
11.1.8.Manually create a call-by-reference using a pointer.