## 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. In the following code fragment, the Boolean expression in the if statement contains an assignment. What output is produced?
```      int x = 1, y = 2 ;

if ( (x = 5) > y )
printf("%d\n", x ) ;
else
printf("%d\n", x + y) ;
```

a. 1
b. 3
c. 5
d. 7

2. Which of the given expressions is equivalent to the following expression for all values of the integer variable i ?
```      (i <= 63) && (i >= 51)
```

a. !( (i > 63) || (i < 51) )
b. !( (i > 63) && (i < 51) )
c. ( (i > 63) || (i < 51) )
d. ( (i &tl;= 63) || (i >= 51) )

3. Which of the following is a function prototype of a function that takes two parameters, an integer and a pointer to an integer, and returns an integer value?
a. void f (int, int) ;
b. int *f (int, int *) ;
c. int f (int *, int *) ;
d. int f (int, int *) ;

4. After the declaration:
```      struct {
int part1 ;
int part2 ;
} foo ;
```

a. foo is a new data type which can be used to declare variables as pointers to a record.
b. foo is a new data type which can be used to declare variables as records.
c. foo is a variable which can hold a pointer to a record.
d. foo is a variable which can hold a record.

5. Suppose that p is a pointer to double and that sizeof(double) is 8. Then the expression p = p + 2;
b. Adds 2.0 to the double variable that p points to.
d. Adds 16.0 to the double variable that p points to.

6. According to the rules of short circuit evaluation, after the following code fragment is executed
```      bool flag = FALSE ;
int a = 1 ;

flag = (a > 1) || ( (a = a + 5) > 4 )
```

a. flag is FALSE and a is 1.
b. flag is FALSE and a is 6.
c. flag is TRUE and a is 1.
d. flag is TRUE and a is 6.

7. In C programming, a recursive function is a function that
a. is written by hand in pseudo-code.
b. makes function calls to many other functions.
c. makes function calls to itself.
d. makes function calls to main.

8. To store the string "CMSC201" you need to allocate:
a. 7 bytes of memory
b. 8 bytes of memory
c. 14 bytes of memory
d. 16 bytes of memory

9. The expression 17/8
a. has type double and value 2.125
b. has type int and value 2.125
c. has type double and value 2.0
d. has type int and value 2

10. What is the value of the following expression?
```       6 - 5 - 4 * 3 / 2 + 1
```

a. -3
b. -2
c. 6
d. -4

11. What is the effect of the following code?
```      int i, sum ;

sum = 1 ;
for (i = 2 ; i <= 5 ; i++) {
sum = sum + i ;
}
printf("%dn", sum) ;
```

a. It prints out the numbers from 1 to 5.
b. It prints out the numbers from 2 to 5.
c. It prints out the sum of the numbers from 1 to 5.
d. It prints out the sum of the numbers from 2 to 5.

12. What is the output of the following code fragment?
```      int n, *p ;

n = 2 ;
p = &n ;
*p = 4 ;
n = *p * n ;
printf("%d %d\n", *p, n) ;
```

a. 4 8
b. 4 16
c. 8 16
d. 16 16