Docsity

Exam 1 with Answer Key - Programming Using C | CGS 3460, Exams of Computer Science

Toggle sidebar
bg1
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.
(a) /*
(b) **
(c) REM
(d) <<
ANS: (a)
2 Which of the following must every C++ program have?
(a) main
(b) #direct
(c) //
(d) <stdio.h>
ANS: (a)
3 Every statement in C must end with a
(a) period (.)
(b) semicolon (;)
(c) colon (:)
(d) backslash (/)
ANS: (b)
4 Which of the following is an escape sequence for ‘next line’?
(a) \n
(b) \\
(c) \~
(d) \”
ANS: (a)
5. The following line is an example of a __________.
printf( “Welcome to C!” );
a) function
b) block
c) statement
d) header
ANS: (c)
1
pf3
pf4
pf5

Partial preview of the text

Download Exam 1 with Answer Key - Programming Using C | CGS 3460 and more Exams Computer Science in PDF only on Docsity!

1/30/04 Signature: __________________________

  1. Lines beginning with the _______________ let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d) << ANS: (a) 2 Which of the following must every C++ program have? (a) main (b) #direct (c) // (d) <stdio.h> ANS: (a) 3 Every statement in C must end with a (a) period (.) (b) semicolon (;) (c) colon (:) (d) backslash (/) ANS: (b) 4 Which of the following is an escape sequence for ‘next line’? (a) \n (b) \ (c) ~ (d) \” ANS: (a)
  2. The following line is an example of a __________. printf( “Welcome to C!” ); a) function b) block c) statement d) header ANS: (c)

1/30/04 Signature: __________________________

  1. In a printf, a backslash is printed by enclosing in quotes a)
    b) \ c) /
    d) // ANS: (b)
  2. The escape sequence for horizontal tab is __________. a) \tab b) \t c) \horizontaltab d) \n ANS: (b)
  3. Which of the following is not a valid integer value? (a) - (b) 0 (c) 2134859 (d) 1. ANS: (d)
  4. Which of the following is an invalid identifier (variable name)? (a) _Test (b) TEST (c) 5test (d) test ANS: (c)
  5. Which statement prints “hi” on the screen? (a) printf("hi"); (b) print "hi"; (c) printf "hi"; (d) none of the above ANS: (a)

1/30/04 Signature: __________________________

  1. Which operation will find the remainder when 15 is divided by 6? (a) 15 / 6 (b) 15 % 6 (c) 15 ^ 6 (d) 15 * 6 ANS: (b)
  2. 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. ANS: (b)
  3. Which of the following is an equality operator? (a) == (b) = (c) > (d) >= ANS: (a)
  4. 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 ANS: (b)
  5. If x = 3, which of the following sets x to 7? (a) x *= 4; (b) x += 4; (c) x =+ 4; (d) x + 4 = x; ANS: (b)

1/30/04 Signature: __________________________

  1. Which assignment expression is equivalent to c = c / 2? a) c /= 2c b) c / c = 2 c) c /= 2 d) c =/ 2 ANS: (c)
  2. Which of the following will not increment variable c by one? (a) c + 1; (b) c++; (c) ++c; (d) c += 1; ANS: (a)
  3. An example of a unary operator is (a) a relational operator (b) an assignment operator (c) an increment operator (d) a logical operator ANS: (c)
  4. Consider the following code, what is the output? int x=12; printf(“%d”, x); (a) 6 (b) 12 (c) nothing (d) a syntax error is produced ANS: (b)
  5. 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 ANS: (b)