我需要创建一个程序,它获取num1,num2及其地址的值以及pNum的值和pNum的derefrenced值。如何获得pNum的值和pNum的解除引用值?
这是到目前为止的代码。
#include <iostream>
using namespace std;
void inputDetails(int* n1, int* n2)
{
if (n1 != nullptr && n2 != nullptr)
{
cout << "Enter two integers" << endl;
cin >> *n1;
cin >> *n2;
}
}
void outputDetails(int num1, int num2)
{
cout << "The value of your first number is " << num1 << endl;
cout << "The value of your second number is " << num2 << endl;
cout << "The address of your first number is " << &num1 << endl;
cout << "The adress of your second number is " << &num2 << endl;
}
int main()
{
int num1, num2;
int temp1, temp2;
int* pNum1 = &num1;
int* pNum2 = &num2;
inputDetails(pNum1, pNum2);
outputDetails(num1, num2);
cin.get();
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
return 0;
}