Isaac H.

asked • 05/09/23

Grab the file arraysWork.cpp.

It will not compile as it has some errors in it. Feel free to remove them when you are working on the code. Your goal is to comment on every single line in the function main except for the return statement with what is being done in this line; for print statements, place what values you see and what these values represent. The lines with errors also must be commented on, so don't forget to return them. What is attempted to be done in the code, and why is it an error?

#include<iostream>
#include<memory>

using std::unique_ptr;
using std::cout;
using std::endl;

int main()
{
int a{ 10 }, b{ 20 };
unique_ptr<int> ap{new int};
*ap = 23;
cout << ap << endl;
cout << *ap << endl;
ap.release();
cout << ap << endl;

unique_ptr<int> ap2 = &a;

unique_ptr<int> ap3{ new int };
*ap3 = 12;
unique_ptr<int> ap4{ new int };
*ap4 = 14;
ap4 = ap3;

return 0; // no need to comment on this line
}

1 Expert Answer

By:

Jonathan M. answered • 05/15/23

Tutor
New to Wyzant

IT Professional Sharing the Knowledge

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.