#include <iostream>
usingnamespace std;
void inputDetails(int* n1, int* n2)
{
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* pNum1 = &num1;
int* pNum2 = &num2;
inputDetails(pNum1, pNum2);
outputDetails(num1, num2);
cin.get();
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
return 0;
}
Thank you! How would i be able to output pnum? I am able to output it in the main function, but i cant figure out how to output it in the outputDetails function.
assuming outputdetails is changed to refer to a pointer now (??)
you can just do
cout << pnum1[0]<< endl;
or (same result)
cout << *pnum1 << endl; // * syntax is confusing when doing math. You get *x * *y type statements. Yuck! I always use array [] notation for that reason.
and the pointer directly
cout << (unsigned int)(pnum) << endl; //the address itself.
if you did not change it to be pointers, it looks a lot like what you already did.
you have to be careful trying to see the address of something after moving it to a parameter. The address of the parameter may not be the address of the thing. I am not sure it would work to take &num in outputdetails to get the address of the arguments ... it may, but I don't remember if you can do that or not. It feels like that would quietly give the incorrect address but someone else can correct me if I am wrong.