CGS3460 – Exam#1 Name: _______ ANSWER KEY _______
1/30/04 Signature: __________________________
1. Lines beginning with the _______________ let the computer know that the rest of the line is a comment.
2 Which of the following must every C++ program have?
3 Every statement in C must end with a
(a) period (.)
(b) semicolon (;)
(c) colon (:)
(d) backslash (/)
4 Which of the following is an escape sequence for ‘next line’?
5. The following line is an example of a __________.
printf( “Welcome to C!” );
6. In a printf, a backslash is printed by enclosing in quotes
7. The escape sequence for horizontal tab is __________.
8. Which of the following is not a valid integer value?
9. Which of the following is an invalid identifier (variable name)?
10. Which statement prints “hi” on the screen?
(b) print "hi";
(c) printf "hi";
(d) none of the above
11. The __________ sign is also known as the __________ operator.
(a) +, assignment
(b) =, assignment
(c) *, stream manipulator
(d) /, stream insertion
12. A(n) __________ is a location in the computer's memory where a value can be stored for use by a program.
13. Which of the following statements is false?
a) C is case sensitive.
b) Uppercase and lowercase letters are different in C.
c) identifier and IdEnTiFiEr are identical identifiers in C.
d) Identifiers can not start with a number.
14. Variable names actually correspond to __________.
(a) locations in the computer's memory
(d) data types
15. When a number gets assigned to a variable that already has a value __________.
(a) the new number overwrites the previous value at that memory location
(b) the new number gets assigned to a neighboring memory location
(c) the computer issues an error
(d) the new value is destroyed and the old value remains
16. Which operation will find the remainder when 15 is divided by 6?
(a) 15 / 6
(b) 15 % 6
(c) 15 ^ 6
(d) 15 * 6
17. Which statement about precedence is false?
a) Parentheses may be used to force the order of evaluation to occur in any sequence desired by the programmer.
b) Nested, or embedded parentheses are evaluated last.
c) Multiplication has a higher precedence than addition.
d) Subtraction has a lower precedence than division.
18. Which of the following is an equality operator?
19. The compile stage is when ____________.
(a) the object code is linked with code for functions in other files
(b) the C program is translated into machine language code
(c) the program is executed one instruction at a time
(d) the program is placed in memory
20. If x = 3, which of the following sets x to 7?
(a) x *= 4;
(b) x += 4;
(c) x =+ 4;
(d) x + 4 = x;
21. Which assignment expression is equivalent to c = c / 2 ?
a) c /= 2c
b) c / c = 2
c) c /= 2
d) c =/ 2
22. Which of the following will not increment variable c by one?
(a) c + 1;
(d) c += 1;
23. An example of a unary operator is
(a) a relational operator
(b) an assignment operator
(c) an increment operator
(d) a logical operator
24. Consider the following code, what is the output?
(d) a syntax error is produced
25. Of the following, which is an error?
(a) putting a space between float and the variable name
(b) dividing by zero
(c) initialize counter to one by using int counter = 1;
(d) no semicolon after #include