# Midterm Exam, version 1, Multiple Choice Section

## Multiple Choice, 2 points each

On lynx, use down arrow to move to the next question or choice. Hit return to make your selection.

1. What is the value of the following expression?
```     13 - 11 - 7 * 5 % 3 + 2 % 1
```

a. -2
b. 0
c. 1
d. 2

2. The expression 13 + 2.5
a. has type double and value 15.5.
b. has type int and value 15.
c. has type double and value 15.
d. has type int and value 16.

3. What is the output of the following code fragment?
```    int a = 3, b = 17 ;

a = b % a ;
b = ++a + 5 ;
printf("a = %d, b = %d\n", a, b) ;
```

a. a = 3, b = 8
b. a = 2, b = 7
c. a = 3, b = 7
d. a = 2, b = 8

4. Execution of a break statement in the body of a for loop
a. causes the entire program to terminate.
b. causes the statement after the switch statement to be executed next.
c. causes the current iteration of the loop to terminate and the next iteration to begin.
d. causes the for loop to terminate and the statement after the body of the for loop to be executed next.

5. Trace the execution of the following if statements and determine the output of the code fragment.
```    int a = 4, b = 3, c = 1 ;

if ( a < b + 1 ) {
printf("Tea, Earl Grey, Hot!\n") ;
} else if ( a > b + c ) {
printf("Ahead warp factor 9. Engage!\n") ;
} else if ( a % b > c ) {
printf("Warp core breach in 20 seconds!\n") ;
} else {
printf("I sense a lot of anxiety in this room.\n") ;
}
```

a. Tea, Earl Grey, Hot!
b. Ahead warp factor 9. Engage!
c. Warp core breach in 20 seconds!
d. I sense a lot of anxiety in this room.

6. What is the effect of the following code?
```    int i, total ;

for (i = 1 ; i <= 15 ; i++) {
if ( i % 3 == 0) printf("%d ", i) ;
}
```

a. It prints out the integers from 3 to 15.
b. It prints out the multiples of 3 from 3 to 15.
c. It prints out the sum of the integers from 3 to 15.
d. It prints out the sum of the multiples of 3 from 3 to 15.

7. Let test be a Boolean variable. Note that there is an assignment in the condition of the first if statement. The output of the following program fragment is:
```    test = FALSE ;
if (test = FALSE) {
printf("Beam down the landing party.\n") ;
} else if (test == FALSE) {
} else {
printf("Scotty, four to beam up.\n") ;
}
```

a. Beam down the landing party.
c. Scotty, four to beam up.
d. No output is produced.

8. The following Boolean expression is equivalent to which of the given expressions?
```    !( (n == 12) || (n > 15) )
```

a. (n != 12) && (n <= 15)
b. (n == 12) && (n > 15)
c. (n != 12) || (n <= 15)
d. (n != 12) && (n < 15)

9. Considering short circuit evaluation, after executing the following statments,
```    int a = 5;
bool test ;

test = (3 > 2) && ( (a = a+3) > 5) ;
test = (a > 7) || ( (a = a+4) > 24) ;
```

a. test is TRUE and a is 12.
b. test is FALSE and a is 5.
c. test is FALSE and a is 9.
d. test is TRUE and a is 8.

10. Which of the following is the function prototype for a function Lwaxana_Troi that takes 2 double parameters and does not return any values.
a. Lwaxana_Troi(double, double)
b. void Lwaxana_Troi(double, double)
c. void Lwaxana_Troi(double x, y)
d. double Lwaxana_Troi(double, double)