Can you fix the syntax and logic errors of the pointer program. Make sure all pr
ID: 3676881 • Letter: C
Question
Can you fix the syntax and logic errors of the pointer program. Make sure all printouts match the label of what to print.
/* d4-3.cpp
This program will print the address, contents, and what
a pointer is pointing at.
Change cout statements to print what label says to print
*/
#include<iostream>
using namespace std;
void printp(int); // make argument a pointer
void pointinput(int); // make argument a pointer
void main()
{
int num;
cout << "Enter an integer into main's num: ";
cin >> num;
printp(num);
cout << "The address of num is num ";
cout << "The value of num is num ";
pointinput(num);
cout << "The address of num is num ";
cout << "The value of num is num ";
}
void printp(int nptr1)
{
cout << "Address of nptr1 accessed from printp is nptr1 ";
cout << "Address of num accessed from printp is num ";
cout << "Value of num accessed from printp is num ";
}
void pointinput(int nptr2)
{
cout << "Enter an integer into main's num from pointinput: ";
cin >> num;
cout << "Address of nptr2 accessed from pointinput is nptr2 ";
cout << "Address of num accessed from pointinput is num ";
cout << "Value of num accessed from pointinput is num ";
}
Explanation / Answer
#include<iostream>
using namespace std;
void printp(int); // make argument a pointer
void pointinput(int); // make argument a pointer
void main()
{
int num;
cout << "Enter an integer into main's num: ";
cin >> num;
printp(&num);
cout << "The address of num is "<<&num<<" ";
cout << "The value of num is "<<num<<" ";
pointinput(&num);
cout << "The address of num is "<<&num<<" ";
cout << "The value of num is "<<num<<" ";
}
void printp(int *nptr1)
{
cout << "Address of nptr1 accessed from printp is "<<nptr1<<" ";
cout << "Address of num accessed from printp is "<<nptr1<<" ";
cout << "Value of num accessed from printp is "<<*nptr1<<" ";
}
void pointinput(int *nptr2)
{
cout << "Enter an integer into main's num from pointinput: ";
cin >> *nptr2;
cout << "Address of nptr2 accessed from pointinput is "<<nptr2<<" ";
cout << "Address of num accessed from pointinput is "<<nptr2<<" ";
cout << "Value of num accessed from pointinput is "<<*nptr2<<" ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.