Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.

Similar presentations


Presentation on theme: "1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009."— Presentation transcript:

1 1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009

2 Consider the loop: for ( int x = 1; x < 5; increment ) cout << x + 1 << endl; If the last value printed is 5, which of the following might have been used for increment? (a) x++ (b) x += 1 (c) ++x (d) Any of the above 2

3 Which of the following for headers is not valid? (a) for( int i = 0; i < 10; i++) (b) int i = 1; for( ; i < 10; i++ ) (c) for( int i = 0, int j = 5; ; i++) (d) for( int i = 0; i < 10; ) 3

4 In a switch structure (a) a break is required after each case (b) multiple actions do not need to be enclosed in braces (c) a default case is required (d) a break is required after the default case 4

5 The following program segment will int counter = 1; do { cout << counter << “ “; } while ( ++counter <= 10 ); (a) print the numbers 1 through 11 (b) print the numbers 1 through 10 (c) print the numbers 1 through 9 (d) cause a syntax error 5

6 In C++, the condition 4 > y > 1 (a) evaluates correctly and could be replaced by ( 4 > y && y > 1 ) (b) does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ) (c) evaluates correctly and could not be replaced by ( 4 > y && y > 1 ) (d) does not evaluate correctly and should not be replaced by ( 4 > y && y > 1 ) 6

7 Consider the following code, assuming that x is an integer variable with an initial value of 12: if( x = 6 ) cout << x; What is the output? (a) 6 (b) 12 (c) nothing (d) a syntax error is produced 7

8 All of the following are true of functions except: (a) they define specific tasks that can be used at many points in a program (b) a function call must specify the name and arguments of the function (c) the definition of a function usually is visible to other functions (d) the implementation of a function is hidden from the caller 8

9 A valid reason for building programs out of functions is (a) that the divide-and-conquer approach facilitates program construction (b) that pre-existing functions can be used to create new programs (c) the avoidance of code repetition within a program (d) all of the above 9

10 The function prototype double mySqrt( int x ); (a) declares a function called mySqrt which takes an integer as an argument and returns a double (b) defines a function called mySqrt which takes an argument of type x and returns a double (c) declares a function called mySqrt which takes a double as an argument and returns an integer 10

11 Which of the following will not produce a syntax error? (a) omitting a return type from a function definition (b) returning a value from a function declared as void (c) declaring a function parameter again inside a function (d) using the same names for arguments passed to a function and the corresponding parameters in the function definition 11


Download ppt "1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009."

Similar presentations


Ads by Google