CS 150 Chapter 6

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

void

Functions that do not have a return type are called ____ functions.

stub

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

a declaration, but not a definition

A function prototype is ____.

automatic

A variable for which memory is allocated at block entry and deallocated at block exit is called a(n) ____________________ variable.

static

A variable for which memory remains allocated as long as the program executes is called a(n) ____________________ variable.

formal

A variable listed in a header is known as a(n) ____ parameter.

actual parameter

A variable or expression listed in a call to a function is called the ____.

reference

A(n) ____________________ parameter is a formal parameter that receives the location (memory address) of the corresponding actual parameter.

value

A(n) ____________________ parameter s a formal parameter that receives a copy of the content of the corresponding actual parameter.

True

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;

98

Assume the following. static_cast<int>('a') = 97 static_cast<int>('A') = 65 The output of the statement: cout << static_cast<int>(tolower('B')) << endl; is ____.

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

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 << myFunc(myFunc(7, 8), 15);

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

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

Given the following function prototype: int test(float, char);, which of the following statements is valid? a. cout << test(12, &); b. cout << test("12.0", '&'); c. int u = test(5.0, '*'); d. cout << test('12', '&');

7

Given the following function: int next(int x) { return (x + 1); } what is the output of the following statement? cout << next(next(5)) << endl;

-1

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;

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

Given the function prototype: float test(int, int, int); which of the following statements is legal? a. cout << test(7, test(14, 23)); b. cout << test(test(7, 14), 23); c. cout << test(14, 23); d. cout << test(7, 14, 23);

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

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

variable

If a formal parameter is a nonconstant reference parameter, during a function call, its corresponding actual parameter must be a(n) ____________________.

void

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.

False

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

scope resolution operator

In C++, :: is called the ____________________.

True

In C++, a function prototype is the function heading without the body of the function.

True

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.

reference

Stream variables (for example, ifstream and ofstream) should be passed by ____________________ to a function.

signature

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

scope

The ____________________ of an identifier refers to where in the program an identifier is accessible (visible).

True

The data type of a variable in a return statement must match the function type.

False

The execution of a return statement in a user-defined function terminates the program.

True

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

False

The following return statement returns the value 10. return 10, 16;

False

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

function header

The heading of the function is also called the ____.

8.0

The output of the statement: cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____.

'$'

The output of the statement: cout << tolower('$') << endl; is ____.

14.0

The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____.

driver

The program that tests a function is called a(n) ____________________ program.

<cmath>

The standard header file for the abs(x)function is ____.

6

The statement: return 2 * 3 + 1, 1 + 5; returns the value ____.

6

The statement: return 37, y, 2 * 3; returns the value ____.

10

The statement: return 8, 10; returns the value ____.

<cctype>

To use the predefined function tolower, the program must include the header file ____.

True

Using functions greatly enhances a program's readability because it reduces the complexity of the function main.

6

What value is returned by the following return statement? int x = 5; return x + 1;

reference

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

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

Which of the following function prototypes is valid? a. int funcExp(int x, float v); b. funcExp(int x, float v){}; c. funcExp(void); d. int funcExp(x);

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

Which of the following function prototypes is valid? a. int funcTest(int x, int y, float z){} b. funcTest(int x, int y, float){}; c. int funcTest(int, int y, float z) d. int funcTest(int, int, float);

b. Prototypes end with a semicolon, but headers do not.

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

Local

____________________ identifiers are not accessible outside of the function (block).

Reference or 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


Set pelajaran terkait

বাংলাদেশের বনভূমি

View Set

aintnoway cuh get me out of here

View Set

Potential Energy & Kinetic Energy 4th Grade Science

View Set

01C - Statistics - Central Tendency, Median

View Set

Chapter 9 & 11: Team Types and Composition

View Set

Chapter 1 Pre & Post Test Questions Oxygen and Medical Gas Therapy

View Set

Chapter 12 - Miscellaneous IP Services - FTP

View Set

Front End Web Developer Interview Prep (HTML, CSS, Javascript, Sass, React)

View Set