#include #include #include using namespace std; /* CSC 7B/FC Quiz 1. Determine if there are memory errors in the following functions, describe the errors and their causes. BE SPECIFIC. Pinpoint the lines that cause the errors and describe the *type* of memory error. */ // a. void f() { char* a = new char[16]; a[0] = 'x'; a[1] = 'y'; a[2] = 0; // "xy" a = new char[4]; a[0] = '1'; a[1] = 0; delete a; } // b. void g() { vector v{1,2,3,4}; for(int x:v) v.push_back(x); } // c. int* h() { int* a = new int[10]; int *b = a; return a; } // d. void h2() { unique_ptr a = make_unique(1); unique_ptr b = make_unique(2); b = move(a); cout << *a << " and " << *b << endl; } /* 2. Is it ever possible to have a memory leak if unique_ptr and make_unique are applied exclusively for heap-allocated memory? YES OR NO. 3.Given unique_ptr a and unique_ptr b, detail the three critical steps that occur during a "move assignment": b = move(a); 4. What is the *default* move semantics of C++ for integers. That is, what happens with int x = 1; int y = move(x); */