{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# ex1solnsp09 - University of Illinois at Urbana-Champaign...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
1. [Pointers, Parameters, and Miscellany – 20 points]. MC1 (2.5pts) Consider the following statements: int *p; int i; int k; i = 37; k = i; p = &i; After these statements, which of the following will change the value of i to 75? (a) k = 75; (b) *k = 75; (c) p = 75; (d) *p = 75; (e) Two or more of the answers will change i to 75. MC2 (2.5pts) Consider the following statements: int i = 1; int k = 2; int * p1; int * p2; p1 = &i; p2 = &k; p1 = p2; *p1 = 3; *p2 = 4; cout << i << endl; Which of the following is printed by the output statement (assume cout works)? (a) 1 (b) 2 (c) 3 (d) 4 (e) None of these. The code does not compile.
MC3 (2.5pts) Consider the following C++ statements: #include <iostream> using namespace std; void increment1(int x) { x = x + 1; } void increment2(int * x) { *(x) = *x + 1; } void increment3(int & x) { x = x + 1; } int main() { int x = 1; increment1(x); increment2(&x); increment3(x); cout << x << endl; return 0; } What is the printed out when this code is compiled and run? (a) 1 (b) 2 (c) 3 (d) 4 (e) This code does not compile. MC4 (2.5pts) Which of the following is a correct way to declare and initialize a dynamic array of length max , each element of which is a List whose parameterized type is a sphere ? (a) List<sphere> * myList = new List<sphere>[max]; (b) sphere ** myList = new sphere *[max]; (c) List<sphere> myList[max]; (d) More than one of (a), (b), (c), are correct. (e) None of (a), (b), (c), are correct.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
MC 5 (5 pts) Find the errors in the following code. Select all that apply, if any. #include <iostream> using namespace std; int * myFun(const int & a) { int * c = new int(a); int b = *c; return &b; } int main() { int n = 8; cout << *(myFun(n)) << endl; return 0; } (a) type mismatch (b) memory leak (c) invalid return value (d) NULL pointer dereference (e) violation of const MC 6 (5pts) Which of the following functions are typically implemented in an iterator class? Check all that apply, if any.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern