{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSE250 MidI1a-solution

# CSE250 MidI1a-solution - Version A Midterm I CSE250 Date...

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

Version A Midterm I, CSE250 Date: Friday. March 4, 2011 Time: 2:00 - 2:50 pm Total Points: 15 There are 4 questions (some with multiple parts). Answer all 4 questions. Name (PRINT, Family-name first: ) UB Person #: Note: Please read and observe the following rules: This is a closes-book exam, closed notes exam. Please leave your UB ID card on the table. Print, in ink, your name, person number. This exam has 7 pages (including the cover). Make sure you have a complete exam booklet. All of your writing must be handed in. This booklet must not be torn or mutilated in any way, and must not be taken from the exam room. Show all your work, unless instructed otherwise. Partial credits may be awarded as appropriate. 0

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

View Full Document
Q1 (2+2+2 = 6 Points) (a) Trace the the following C++ program segment. What will be the output? void Increase(int & x, int y) { x = x + 1; y = y + 2; } int main() { int a=1; int b=5; cout << "a= " << a << " b=" << b << endl; Increase(a,b); cout << "a= " << a << " b=" << b << endl; } Solution : a = 1 ,b = 5 (1 point) a = 2 ,b = 5 (1 point) (b) What will be the output from the following C++ program segment. (If a statement causes error, or produces uncertain output, please explain why.) int main() { int* p = new int(20); int* q = p; int a = -10; (*q) = 10; cout << "(*p)=" << *p << endl; q = &a; cout << "(*q)=" << *q << endl; } Solution : ( * p ) = 10 (1 point) ( * q ) = - 10 (1 point) 1
c) What will be the output from the following C++ program segment.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}