C++ Functions - Study Guide

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Given the following function: int next(int x) { return (x + 1); } what is the output of the following statement? cout << next(next(5)) << endl; A.) 5 B.) 6 C.) 8 D.) 7

D.) 7

The standard header file for the abs(x)function is ____. A.) <cctype> B.) <ioinput> C.) <cstdlib> D.) <cmath>

D.) <cmath>

Which of the following function prototypes is valid? A.) int funcTest(int x, int y, float z){} B.) int funcTest(int, int y, float z) C.) funcTest(int x, int y, float){}; D.) int funcTest(int, int, float);

D.) int funcTest(int, int, float);

Given the following function prototype: ​ int test(float, char); ​ which of the following statements is valid? A.) cout << test(12, &); B.) cout << test('12', '&'); C.) cout << test("12.0", '&'); D.) int u = test(5.0, '*');

D.) int u = test(5.0, '*');

True or False: If the formal parameter list of a function is empty, the parentheses after the function name are not needed.

False

True or False: The execution of a return statement in a user-defined function terminates the program.

False

True or False: The following return statement returns the value 10. return 10, 16;

False

True or False: The function main is always compiled first, regardless of where in the program the function main is placed.

False

Given the following function: int strange(int x, int y) { if (x > y) return x + y; else return x - y; } what is the output of the following statement? cout << strange(4, 5) << endl; A.) -1 B.) 20 C.) 9 D.) 1

A.) -1

The statement: return 2 * 3 + 1, 1 + 5; returns the value ____. A.) 6 B.) 2 C.) 3 D.) 7

A.) 6

What value is returned by the following return statement? int x = 5; return x + 1; A.) 6 B.) 7 C.) 0 D.) 5

A.) 6

The output of the statement: cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____. A.) 8.0 B.) 7.0 C.) 9.0 D.) 6.0

A.) 8.0

Given the following function prototype: ​ int myFunc(int, int); ​ which of the following statements is valid? Assume that all variables are properly declared. A.) cout << myFunc(myFunc(7, 8), 15); B.) cin >> myFunc(y); C.) cout << myFunc(myFunc(7), 15); D.) cin >> myFunc('2', '3');

A.) cout << myFunc(myFunc(7, 8), 15);

Given the function prototype: float test(int, int, int); which of the following statements is legal? A.) cout << test(7, 14, 23); B.) cout << test(7, test(14, 23)); C.) cout << test(test(7, 14), 23); D.) cout << test(14, 23);

A.) cout << test(7, 14, 23);

A variable listed in a header is known as a(n) ____ parameter. A.) formal B.) local C.) actual D.) function

A.) formal

Functions that do not have a return type are called ____ functions. A.) void B.) null C.) empty D.) zero

A.) void

The statement: return 8, 10; returns the value ____. A.) 18 B.) 10 C.) 8 D.) 80

B.) 10

Which statement below about prototypes and headers is true? A.) Headers should come before prototypes B.) Prototypes end with a semicolon, but headers do not C.) Headers end with a semicolon, but prototypes do not D.) Parameter names must be listed in the prototype, but not necessarily in the header

B.) Prototypes end with a semicolon, but headers do not

A function prototype is ____. A.) a definition, but not a declaration B.) a declaration, but not a definition C.) a comment line D.) a declaration and a definition

B.) a declaration, but not a definition

Given the function prototype: ​ double testAlpha(int u, char v, double t); ​ which of the following statements is legal? A.) cout << testAlpha('5.0', 'A', '2.0'); B.) cout << testAlpha(5, 'A', 2); C.) cout << testAlpha( int 5, char 'A', int 2); D.) cout << testAlpha(5.0, "65", 2.0);

B.) cout << testAlpha(5, 'A', 2);

Given the following function prototype: ​ double tryMe(double, double); ​ which of the following statements is valid? Assume that all variables are properly declared. A.) cin >> tryMe(x); B.) cout << tryMe(2.0, 3.0); C.) cout << tryMe(tryMe(double, double), double); D.) cout << tryMe(tryMe(float, float), float);

B.) cout << tryMe(2.0, 3.0);

The heading of the function is also called the ____. A.) function head B.) function header C.) title D.) function signature

B.) function header

The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____. A.) 13.0 B.) 12.0 C.) 14.0 D.) 11.0

C.) 14.0

The statement: return 37, y, 2 * 3; returns the value ____. A.) 2 B.) y C.) 6 D.) 3

C.) 6

A variable or expression listed in a call to a function is called the ____. A.) formal parameter B.) data type C.) actual parameter D.) type of the function

C.) actual parameter

Which of the following function prototypes is valid? A.) int funcExp(x); B.) funcExp(void); C.) int funcExp(int x, float v); D.) funcExp(int x, float v){};

C.) int funcExp(int x, float v);

When you attach & after the dataType in the formal parameter list of a function, the variable following that dataType becomes a(n) ____________________ parameter.

reference

____________________ parameters are useful in three situations: • When the value of the actual parameter needs to be changed • When you want to return more than one value from a function • When passing the address would save memory space and time relative to copying a large amount of data

reference

The ____________________ of a function consists of the function name and its formal parameter list.

signature

A function ____________________ is a function that is not fully coded.

stub

If a function needs to return more than one value, as a rule of good programming style, you should change it to a(n) ____________________ function and use the appropriate reference parameters to return the values.

void

True or False: Assume that all variables are properly declared. The following statement in a value-returning function is legal. if (x % 2 == 0) return x; else return x + 1;

True

True or False: In C++, a function prototype is the function heading without the body of the function.

True

True or False: Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly.

True

True or False: The data type of a variable in a return statement must match the function type.

True

True or False: The following function heading in a C++ program is valid: int funcExp(int u, char v, float g);

True

True or False: Using functions greatly enhances a program's readability because it reduces the complexity of the function main

True


Kaugnay na mga set ng pag-aaral

Security + 501 Chapter 5 Risk Management

View Set

Ch 39 Nursing assesement: GI practice questions

View Set

Amboss Rheumatology and Immunology

View Set

Seven Wonders of the Ancient World

View Set

Chapter 30 - Listening Guide Quiz 20: Haydn: Symphony No. 94 in G Major (Surprise), II

View Set