exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the output of the following code segment? int n = 1; for ( ; n <= 5; ) { cout << n << ' '; n++; } a) 1 2 3 4 5 b) 2 3 4 5 6 c) 1 1 1 ... and on forever d) 2 3 4 5 e) 1 2 3 4

a) 1 2 3 4 5

. Look at the following function prototype. int myFunction(double); What is the data type of the function's return value? a) int b) double c) void d) Can't tell from the prototype

a) int

What will the following loop display? int x = 0; while (x < 5) { cout << x << " "; x++; } a) 0 1 2 3 4 5 b) 0 1 2 3 4 c) 01 2 3 4 d) The loop will display numbers starting at 0, for infinity

b) 0 1 2 3 4

What is the output of the following code segment? int n = 1; while (n <= 5) cout << n << ' '; n++; a) 1 2 3 4 b) 1 1 1... and on forever c) 1 2 3 4 5 d) 2 3 4 5 e) 2 3 4 5 6

b) 1 1 1... and on forever

A for statement contains three expressions: initialization, test, and a) validation b) update c) null d) reversal

b) update

What is the output of the following program? #include <iostream> using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << " "; return 0; { void showDub(int num) { cout << (num * 2) << " "; } a) 4 4 b) 2 4 c) 4 2 d) 2 2

c) 4 2

double compute(double, double, double &); ... double compute(double a, double, b, double & c) { ... } When we call the function compute we say that the arguments: a) a and b are passed by reference, c by value b) a, b, and c are all passed by value c) a and b are passed by value, c by reference d) a, b, and c are all passed by reference

c) a and b are passed by value, c by reference

A function is executed when it is a) declared b) defined c) called d) prototyped

c) called

Relational operators allow you to ____________ numbers. a) average b) add c) compare d) multiply

c) compare

What is assigned to the variable a given the statement below with the following assumptions: x = 6, y = 7, and z, a, and b are all int variables? a = x++ >= y;

d) 0

Given the following function definition void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; a) 1 2 3

d) 1 6 3

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int); int main() { int x = 2; cout << x << " "; doSomething(x); cout << x << " "; return 0; } void doSomething(int num) { num = 0; cout << num << " "; } a) 2 2 2 b) 2 0 0 c) 0 0 0 d) 2 0 2

d) 2 0 2

What will the following code display? int number = 6; cout << ++number << endl; a) 5 b) 6 c) 0 d) 7

d) 7

When we pass a variable by reference, where must the address of operator & be placed? a) In the function header only b) In the prototype only c) In the function call statement only d) In the prototype and the function header e) In the prototype, the function header and the function call statement f) We don't have to place it anywhere, variables are passed by reference by default

d) In the prototype and the function header

This is a variable that is regularly incremented or decremented each time a loop iterates. a) constant b) null terminator c) control statement d) counter

d) counter

This type of variable is defined inside a function and is not accessible outside the function. a) counter b) reference c) global d) local

d) local

When an if statement is placed within the conditionally-executed code of another if statement, this is known as: a) complexity b) overloading c) validation d) nesting

d) nesting

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n): a) post-test loop b) pre-test loop c) finite loop d) null statement

d) null statement

In a function header, you must furnish (check all that apply) a) data type of the return value b) the name of function c) names of parameter variables d) data type(s) of the parameters

(check all)

A function can have zero to many parameters, and it can return this many values. a) none b) a maximum of 10 c) zero to many d) only one

...

This operator increments the value of its operand by one, then uses the value in context. A) prefix increment B) postfix increment C) prefix decrement D) postfix decrement E) None of these

A) prefix increment

A function prototype is declared A) typically before the main function B) always after the main function C) as the first statement in main D) none of the above

A) typically before the main function

Look at the following statement. while (x++ < 10)... Which of these is accessed first: A) ++ B) < C) Neither. The expression is invalid.

B) <

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop. A) infinite B) for C) do-while D) while

B) for

The value in this type of local variable persists between function calls. A) None of these B) static C) internal D) dynamic E) global

B) static

How many times will the following loop display "Hello"? for (int i = 0; i <= 20; i++) cout << "Hello!" << endl; A) 20 B) 19 C) 21 D) An infinite number of times

C) 21

Look at the following function prototype: int myFunction(double); What is the data type of the function's parameter variable? A) int B) void C) double D) Can't tell from the prototype

C) double

This statement causes a function to end. A) end B) terminate C) return D) release E) None of these

C) return

What will the following code display? int number = 6; cout << number++ << endl; A) 7 B) 0 C) 5 D) 6

D) 6

. What will the following code display? int number = 6; number++; cout << number << endl; A) 5 B) 0 C) 6 D) 7

D) 7

Input values should always be checked for A) Appropriate range B) Reasonableness C) Division by zero, if division is taking place D) All of these E) None of these

D) All of these

This is a variable, usually a boolean or an integer, that signals when a condition exists. A) float B) relational operator C) None of these D) flag E) arithmetic operator

D) flag

A function __________ eliminates the need to place a function definition before all calls to the function. A) argument B) header C) None of these D) prototype E) parameter

D) prototype

Examine the following code segment: (y < z) ? x = 11 : x = 12; This is an example of: A) a shortened version of an if-else statement B) a conditional expression C) an invalid C++ statement D) a shortened version of an if-else-if statement E) both a and b are correct F) None are correct

E) both a and b are correct


Conjuntos de estudio relacionados

EXAM 3 Ch. 22 Management of the Postpartum Woman at Risk, Maternity - Chapter 21_Exam#3, Chapter 20 e3, Chapter19-Nursing Management of Pregnancy at Risk-Pregnancy E3

View Set

Chabner chapter 11 medical terminology

View Set

All Multiple Choice (Modes #1-#5)

View Set

POLS 1337 FED Chapter 13 The Presidency Part 2

View Set

Porth's Patho: Bladder & Lower Urinary Tract, Chapter 35

View Set