[an error occurred while processing this directive]
CMSC 201 Quiz 1 --- February 20, 1996
Answers are in bold and red .
Thought for the day: What gets us into trouble is not
what we don't know. It's what we know for sure that just ain't
so. -- Yogi Berra
1. True/false questions
Circle T or F for TRUE and FALSE respectively for each of
the following question. (Five point each.)
- TRUE (17%2 == 17%4)
- TRUE All variables in a C program must be explicitly declared.
- FALSE
A variable declaration sets the value of double variables to 0.0.
- TRUE
The expressions 5.0 / 2 and 5 / 2.0 are equivalent.
- FALSE
"Cascading if statements" should not be used when writing C programs.
- TRUE
The printf function is one of several functions defined in the C
standard I/O library commonly known as stdio.h.
- FALSE
a flag is another word for an index variable in a loop.
- FALSE
In C, semicolons should only be placed between pairs of adjacent statements.
- FALSE
According to DeMorgan's laws, ((!(A && B)) == ((!A) && (!B))) for all boolean variables A and B.
- TRUE
Every for loop can be converted into an equivalent while loop.
2. Which of the following is a legal identifier in C? (five
points)
- (a.) NINE_TO_FIVE
- (b.) 9_to_5
- (c.) This_identifier_may_be_too_long
- (d.) All of the above.
- (e.) Only a and c.
3. Which of the following is a C language keyword? (five points)
- (a.) main
- (b.) int
- (c.) while
- (d.) Only b and c.
- (e.) None of the above, since C doesn't have keywords.
4. Printf format codes.
Which of the following format codes could be used to print a floating
point value in a printf statement? (Five points)
- (a.) %d
- (b.) %f
- (c.) %g
- (d.) Only b and c.
- (e.) All of the above.
5. What is the value of the following expression?
(Five points)
7 + 2 / 3 - 4 + 4 / 3
- (a.) 4
- (b.) 5
- (c.) 0
- (d.) None of the above.
In the problems below, Show the output of the following program
fragments. Assume everything compiles correctly and don't wory about
the exact number of spaces to appear before or after any numeric
output.
6. Shorthand expressions (10 points)
int a, b;
a = 11;
b = 27;
a++;
a += b;
b = a - b;
a -= b;
printf("a is %d and b is %d\n", a, b);
a is 27 and b is 12
7. Plus-plus (10 points)
int i, j, k;
i = j = 0;
k = 3;
while ( (i+j) < k) {
i++; j++; k++;
printf("End of pass %d: j=%d and k=%d\n",i,j,k);
}
End of pass 1: j=1 and k=4
End of pass 2: j=2 and k=5
End of pass 3: j=1 and k=6
8. Data type conversion (10 points)
#define pi 3.1416
int a;
double b;
float c;
b = a = pi*2.0;
c = (int) pi + a
printf("a is %d b is %f c is %f\n,a,b,c);
a is 6 b is 6.000000 c is 9.000000
9. Extra credit (1 point)
int i;main(){for(;i["]
hello, world!
[an error occurred while processing this directive]
Tuesday, 20-Feb-1996 21:30:57 EST