Sample Midterm: .edu



CSE/ENGR 142 – 1998, Autumn

Midterm 1, Version B

Part I: Multiple Choice (72 points)

Answer all of the following questions. READ EACH QUESTION CAREFULLY. Fill the correct bubble on your mark-sense sheet. Each correct question is worth 4 points. Choose the one BEST answer for each question. Assume that all given C code is syntactically correct unless a possibility to the contrary is suggested in the question.

Remember not to devote too much time to any single question, and good luck!

| |"C is strongly typed" means... |

| |A. |you need strong typing and keyboarding skills to be a C programmer. |

| |B. |there is a strongly defined type or category to which the C programming language belongs. |

| |C. |every value has a type, and C cares about what those types are. |

| |D. |you can never assign a variable of type int to a variable of type double. |

| |E. |C checks type matching in all places where it matters, such as checking that a placeholder type letter (%d, %f, |

| | |etc.) matches the type of the corresponding variable). |

| |Answer: C |

| |Which of the following could NOT be a variable name in C? |

| |A. |1st_value |

| |B. |v300000 |

| |C. |integer |

| |D. |Double |

| |E. |_rock_it__duuude |

| |Answer: A |

| |What is the value of the following expression (given the following declarations)? |

| | |

| |int a = 8; |

| |int b = 2; |

| |int c = 4; |

| | |

| |a + b / c * a - c / b |

| |A. |10.0 |

| |B. |4 |

| |C. |6 |

| |D. |10 |

| |E. |8 |

| |Answer: C |

| |Which of the following was NOT given as a motivation for using functions in programming? |

| |A. |Functions raise the level of discourse. |

| |B. |Functions are more efficient (run faster) than the same solution without functions. |

| |C. |That's how modern programming is done. |

| |D. |Functions permit code to be shared between programs. |

| |E. |Functions make it easier to perform the same computation over and over again. |

| |Answer: B |

| |Suppose x is a double. After the statements |

| |x = 5.9; |

| |a = (int) x; |

| |have executed, what is the value of x? |

| |A. |5.9 |

| |B. |5 |

| |C. |5.0 |

| |D. |6 |

| |E. |Depends on how a was declared |

| |Answer: A |

| |Choose the best conclusion to the statement. |

| |In C, the word double… |

| |A. |is a special, floating point value. |

| |B. |is a reserved word. |

| |C. |must be part of the declaration of every variable which will hold numeric values. |

| |D. |indicates the operation "multiply by 2.0" |

| |E. |is available for use as a variable name. |

| |Answer: B |

| |Suppose # is a left-associative binary operator which has lower precedence than +. Given the following expression, |

| |which expression is equivalent to it? |

| |3 + 5 # 6 # 7 |

| |A. |3 + (5 # (6 # 7)) |

| |B. |(3 + 5) # (6 # 7) |

| |C. |3 + ((5 # 6) # 7) |

| |D. |((3 + 5) # 6) # 7 |

| |E. |(3 +( 5 # 6)) # 7 |

| |Answer: D |

| |For the operators *, +, /, %, -, which of the following statements about precedence in C is true: |

| |A. |Highest *, /, % |

| | |Lowest +, - |

| |B. |Highest +, /, * |

| | |Lowest %, - |

| |C. |Highest *, %, - |

| | |Lowest /, + |

| |D. |Highest *, +, % |

| | |Lowest -, / |

| |E. |Higest *, / |

| | |Lowest +, -, % |

| |Answer: A |

| |If you see the following line in an error-free C program: |

| | |

| |y = combine (a / b + c); |

| | |

| |which statement could not be true: |

| |A. |b is used in this line as an argument (actual parameter) of combine. |

| |B. |combine does not have a "void" return value. |

| |C. |The definition of combine contains one and only one return statement. |

| |D. |The definition of combine does not have a "void" parameter list. |

| |E. |The function combine has three formal parameters. |

| |Answer: E |

| |Suppose a valid C program contains the statement |

| |TREE = TRUNK; |

| | |

| |Which of the following is true? (Don't assume anything about the style used in naming identifiers.) |

| |A. |TREE and TRUNK must both be #defines. |

| |B. |TREE must be a #define but TRUNK doesn't have to be. |

| |C. |TRUNK must be a #define but TREE doesn't have to be. |

| |D. |TREE cannot be a #define but TRUNK might be. |

| |E. |Neither TREE nor TRUNK could be a #define. |

| |Answer: D |

| |In C, the value of a condition can be thought of informally as "yes" or "no" but is actually represented by the values |

| |A. |true or false |

| |B. |TRUE or FALSE |

| |C. |-1 or 1 |

| |D. |ON or OFF |

| |E. |non-zero (usually 1) or 0 |

| |Answer: E |

| |#include |

| | |

| |int F1 (int a) { |

| |a = 2; |

| |return 3; |

| |} |

| | |

| |int main (void) { |

| |int a; |

| |a = 0; |

| |a = 4; |

| |a = F1 (a); /*line 1*/ |

| |printf ("a = %d", a); |

| |return 0; |

| |} |

| | |

| |When this program runs, what will it display (assume no syntax errors, except possibly as indicated in the answers) |

| |A. |a = 0 |

| |B. |a = 2 |

| |C. |a = 3 |

| |D. |a = 4 |

| |E. |Won't run: line 1 has a syntax error |

| |Answer: C |

| |The following function is supposed to find the smallest among four characters. Choose the best answer. |

| | |

| |char smallest_of_4 (char c1, char c2, char c3, char c4) { |

| |char smallest_of_1and2, smallest_of_3and4, smallest_of_all; |

| | |

| |if (c1 ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download