Quiz 1

True or False Questions, 1 point each

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

1. An integer variable that has never been assigned any value must have the value 0.

2. The main reason to use good indentation in a C program is to make it readable.

3. The purpose of a compiler is to turn source code into machine language.

4. The fraction 1/5 can be stored exactly (without round-off error) in a double variable.

5. The value of the expression 23%3 is 3.

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. Consider the integer expression (17+3)*(14+9)+3. The fact that multiplication has higher precedence than addition tells you that:

a. The expression (17+3) is evaluated before (14+9)+3.
b. The expression (17+3) is evaluated after (14+9)+3.
c. The expression above is equivalent to (17+3)*((14+9)+3).
d. The expression above is equivalent to ((17+3)*(14+9))+3.

2. Consider the integer expression (4+5)-(7+9)-(2+4). The fact that subtraction associates left to right tells you that

a. The expression (4+5) must be evaluated before the expression (7+9).
b. The expression (7+9) must be evaluated before the expression (2+4).
c. The expression above is equivalent to ((4+5)-(7+9))-(2+4).
d. The expression above is equivalent to (4+5)-((7+9)-(2+4))

3. Which of the following is not an integer expression?

a. 14%3
b. 14/3.0
c. (int)(14.0/3.0)
d. 14/3

4. Which of the following expressions does not have a side effect?

a. i == 17 - i
b. n = GetInteger()
c. n = m = 0
d. i++= 17 - i

5. Which of the following statements correctly describes the expression:
```	    (n = 3) * 2 + (n = n + 10) * 4
```

a. The expression has a syntax error.
b. The = symbols should be replaced by ==.
c. A program containing this expression will crash if the expression is executed.
d. The value of the expression depends on which compiler is used.

1. Write down the output of the following program fragment.
```	int n ;

n = 3 ;
if (n != 3) {
printf("Captain Fantastic\n") ;
} else if (n * 2 <= 5 + n) {
printf("Brown Dirt Cowboy\n") ;
} else {
printf("Rocket Man\n") ;
}
```
Sample Solution

2. What is the output of the following code fragment?
```	int i;

for (i = 0 ; i < 9 ; i = i + 2) {
printf("%d\n", 2 * i) ;
}

```
Sample Solution

3. What is the output of the following code fragment?
```	int n, m ;

n = 1 ;
m = 1 ;
while (n < 30) {
printf ("n = %d, m = %d\n", n, m) ;
m = m + 2 ;
n = n + m ;
}
```
Sample Solution