chapter 6 part 1, 2, 3, & 4.

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

False

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

False

int foo (char letter) { switch (letter) { case 'a': case 'b': case 'c': return letter - 'a'; } return ?; } What is the value of the val of the following function call? char test = 'c'-1; int val = foo(test)

'b' - 'a'

Given the following function: int strange(int num1, int num2) { if (num1 > num2) return num1 + num2; else return num1 - num2; } what is the output of the following statement? cout << strange(4, 5) << endl;

-1

Int count (int num) { int result =0; while (num > 1) { result += num; --num; } return result; } The return value of the following function call is _______.

0 OR zero

#include <iostream> using namespacestd; void calc(int& p1, int p2); int glob; int main() { int num1=12; int num2 =5; glob =100; cout << num1 << ' ' << num2 << ' ' << glob << '\n'; calc(num1, num2); cout << num1 << ' ' << num2 << ' ' << glob << '\n'; return 0; } void calc(int& p1, int p2) { glob = 2*p1; p2/ =2; p1 = p; } the numric output is:

12,5,100,2,5,24

"Hello" is output times in the following program. #include <iostream> #include ‹string> using namespace std; const int TIMES = 4; void message(const string& text); int main() { for (int iter = 0; iter < TIMES; ++iter) message ("hello"); return 0; } void message(const string& text). { for (int iter = TIMES; iter > 0; --iter) cout «< text << endl; }

16 or sixteen

What value is returned by the following return statement defined inside of a function? int upper = 5; return upper % 3;

2

What value is returned by the following return statement defined inside of a function? int upper = 5; return upper % 4;

5

Given same code in 13. int test =3; count(test); The return value of the following function call is ______

5 OR five

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

8.0

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

constant

String values should always be passed as _________ instead of pass by value.

constant reference

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

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

a function ______ tells the complier the name, parameter types, and return type.

declaration

A function ______ contains the function header and body, which contains the statements that the function carries out.

definition

Select the prototype that is an invalid overload of this function prototype: int negate(int value);

double negate (int value)

default parameters are defined in _________

function prototype

given the following function prototype, adding the additional prototype _________ will result in a complier error. bool initiateDestructSeqence();

int initiateDestructSeqence();

Given the following function prototype: int test(double distance, char indicator);, which of the following statements is valid? cout << test(12, &); cout << test("12.0", '&'); int u = test(5.0, '*'); cout << test('12', '&');

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

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

local

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

a formal parameter that receives the location (memory address) of the corresponding actual parameter is a pass by

reference

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

scope

A variable for which memory is allocated as long as the program executes is call a(n) ___________ variable.

static

A formal parameter that receives a copy of the content of the corresponding actual parameter is pass-by-____________________.

value

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

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.

void

Given the following code: String text (string input) { return input; input = "Goodbye"; } What is the output of the following statements? String stuff = "Hello"; cout << stuff << endl; cout << text (stuff) << endl; cout << stuff << endl;

Hello Hello Hello

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

Prototypes end with a semicolon, but headers do not.

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

True

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

True

Given the following code, const int MAX = 100; string validator( bool valid) { return valid ? "yes" : "no"; } What is the return value of the following function call? validator(30 <= MAX / 2);

YES

A function prototype is ____.

a declaration, but not a definition


Ensembles d'études connexes

Chapter 22 "Nursing Care of Patients With Hypertension"

View Set

EMT Chapter 20: Immunologic Emergencies

View Set

Computers Chapter 1: Digital Literacy

View Set

Quiz: Using Windows Task Manager to Evaluate System Performance

View Set