DOC PREVIEW
UW CSE 142 - Exam Guide

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers suggests otherwise. What is printed by the following program fragment? int p_test (int a, int * b) { int d; d = a - *b; a = d; *b = d: return d; } int main (void) { int a=1, b=2, c=3, d=4; c = p_test (a, &b); printf ("%d %d %d %d", a, b, c, d); ... A. 1 2 3 4 B. -1 -1 -1 -1 C. 1 -1 -1 4 D. -1 -1 -1 4 1. E. 1 -1 -1 -1 What does the following code print? (Assume the program compiles without error). Trick question! Note the semicolon at the end of the second line. int i; for(i = 1; i <= 10; i = i + 1); printf("%d", i); A. the numbers 1 through 10 B. the number 1 (only) C. the number 10 (only) D. the number 11 (only) 2. E. can’t tell, because i is not initialized What is the output of the following program fragment? x = 6; y = 5; z = 1; if (x <= y || y <= z) printf ("Yellow"); else printf ("Green"); A. No output, because the printf doesn’t have a % (placeholder). B. Can’t tell, because (x <= y || y <= z) is not legal C (is a syntax error). C. Yellow D. Green 3. E. YellowGreenPage 2 What is the output of the following program? #include <stdio.h> void F(int a, int b) { int c; c = a; a = b; b = c; } int main (void) { int a,b,c; a = 5; b = 4; c = 10; F (a, b); printf ("a=%d b=%d c=%d", a, b, c); return 0; } A. a=1 b=5 c=10 B. a=5 b=4 c=10 C. a=5 b=4 c=4 D. a=4 b=5 c=5 4. E. a=21 b=22 c=23 Which of these three program fragments have the same output (apart from spacing)? All variables are ints. i. printf("1\n2\n3\n4\n5\n6\n7\n8\n9\n"); ii. for (i = 9; i > 0; i--) { j = i - 10; printf("%d\n", -j); } iii. i = 1; while (i < 10) { printf("%d\n", i); i++; } A. i. and ii. B. ii. and iii. C. i., ii., and iii. D. None have the same output 5. E. i. and iii.Page 3 Consider the following program fragment: ... double taxes[3]; double total; total = taxes[1] + taxes[2] + taxes[3]; /* line A */ Choose the best statement: A. Line A is wrong because of an out-of-bounds error B. Line A is correct, but for the sake of efficiency, line A should be rewritten as a for-loop. C. Line A can be written more efficiently as total += taxes[ ]; D. Line A has a logic error because total is not initialized. 6. E. There is no logic or syntax error in line A. The following program fragment has its lines numbered for reference along the left-hand side. The code prints a figure that looks like this: * ** *** **** 1) #define SIZE 4 ... 2) int col; 3) int row = 1; 4) while (row <= SIZE) { 5) col = 1; 6) while (col <= row){ 7) printf("*"); 8) col = col + 1; } 10) printf("\n"); 11) row = row + 1; } ... Suppose we wanted the output look like this instead: **** *** ** * What changes to the code would accomplish this? A. 3) int row = 4; 4) while (row >= 1){ 11) row = row - 1; B. 1) #define SIZE (-4) C. 5) col = 4; 6) while (col >= row){ D. 3) int row = 4; 11) row = row - 1; 7. E. 5) col = 4;Page 4 What values of a, b, and c (respectively) make the following condition evaluate to "true" (or 1) ? ( !(b && a) && (c && b) ) I) 0,0,0 II) 1,1,1 III) 1,1,0 IV) 1,0,0 A. I, II, and III only B. II and IV only C. IV only D. There are some combinations of values which make it true, but none are listed among the choices 8. E. There exists no combination of values make this expression true What is true about compound statements in C? A. A compound statement must contain at least one statement. B. A compound statement cannot contain another compound statement C. A compound statement cannot contain any function calls A. A only B. B only C. C only D. None of A, B, or C 9. E. All of A, B, and C If x (an integer variable) has the value 1 at the start of the following code fragment, what is its value at the end? if (x < 0 || x == 3) { x = x - 1; } if ( x < 2*x && x - 2 < 0) { x = x + 1; } else { x = x + 3; } A. 0 B. 1 C. 2 D. 3 10. E. 4 Which of the following does not itself cause a change in the sequential control flow of a program in execution? A. assignment statement B. function call C. return statement D. switch statement 11. E. if statementPage 5 A "sentinel" in programming, as we have used it, is... A. a statement which checks for an error B. a special value on input C. the vertical bar character used in the "or" operation D. a peer or colleague who reads a program to check for errors 12. E. any warning or error when a program is compiled Among the choices offered, which condition is equivalent to the following (assume the variables are chars): (answer != ’y’) && (option == ’q’) A. !((answer != ’n’) && (option != ’q’)) B. !(answer == n’) && !(option == ’q’) C. (an swer == ’y’) || (option != ’q’) D. (answer !(!= ’y’)) || (option !(!= ’q’)) 13. E. !((answer == ’y’) || (option != ’q’)) Suppose that the function Snipe begins void Snipe(int *f, double d, char *ch){ int i, j; double x, y; char a, b; ... What are the types of the three expressions: (int) *ch + i *d / *f *f < i A. int*, double, &int B. int, illegal, int C. char, double, illegal D. illegal, illegal, int 14. E. int, illegal, int*Page 6 The function AddOne can be used to increment a variable. The code for AddOne is: void AddOne(int *x){ *x = *x + 1; } Which of the following is a correct implementation of the AddTwo function, which adds two to a variable: A. void AddTwo(int *y){ AddOne(&y); AddOne(&y); } B. void AddTwo(int *y){ AddOne(y); AddOne(y); } C. void AddTwo(int *y){ AddOne(*y); AddOne(*y); } D. void AddTwo(int y){ y = y + 2; } 15. E. void AddTwo(int *y){ int temp; temp = *y; AddOne(&temp); AddOne(&temp); } Here is an incomplete truth table for !(P&&Q). If the last column were filled in, how many T’s would that column contain? P Q !(P&&Q) --------------------------------------- T T T F F T …


View Full Document

UW CSE 142 - Exam Guide

Download Exam Guide
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam Guide and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam Guide 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?