Cpp - Write program to use dereferenced pointer to change the values' content.

Requirements

Write program to use dereferenced pointer to change the values' content.

Demo

#include <iostream>
  
int main()/*from ww w.j a va  2 s.  c o m*/
{
    unsigned short int myAge = 5, yourAge = 10;
    unsigned short int *pAge = &myAge;  // a pointer
  
    pAge = &yourAge;       // reassign the pointer

    *pAge = 12;

    std::cout << "\npAge:\t" << pAge << "\n";
    std::cout << "*pAge:\t" << *pAge << "\n\n";

    return 0;
}

Result

Related Exercise