Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that defines an integer variable nNum and a pointer variable pnN

ID: 3940236 • Letter: W

Question

Write a program that defines

an integer variable nNum and a

pointer variable pnNum that points to the address of the integer

nNum.

Define two constant string variables sznNum = “nNum” and

szpnNum = “pnNum”. Your program should ask a user to enter an

integer for nNum. You should then ask the user to enter a

second

integer. You must use the pointer pnNum to change the value of

nNum. Be sure to display the address and value of nNum, the

address to which pnNum points, and the value of nNum after being

changed by the pointer. When displaying values, use the

string

variable references sznNum and szpnNum whenever you need to

display the variable names nNum and pnNum.

Explanation / Answer

// Example program
#include <iostream>
#include <string>
using namespace std;

int main()
{
int nNum;
int *pnNum=&nNum;
const string sznNum="nNum";
const string szpnNum="pnNum";
cout << "Please enter an integer value: ";
cin >> nNum;
cout<<"Value of "+ sznNum +" is " << nNum << " ";
cout<<"Address of "+ sznNum +" is " << &nNum << " ";
cout<<"Adress to which "+ szpnNum +" points is " << pnNum << " ";

cout << "Please enter a second integer value: ";
cin >> *pnNum;

cout<<"Value of "+ sznNum +" after being changed by pointer is " << nNum << " ";

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote