C++ chapter 6 Functions

Ace your homework & exams now with Quizwiz!

Can you use a parameter variable to initialize a local variable?

Yes, because the scope of a parameter variable is the entire function in which it is declared, you can use parameter variables to initialize local variables.

global constant

a named constant that is available to every function in a program.Because a global constant's value cannot be changed during the pogram's execution, you don't need to wory about the problems with global variables.

Modular program

a program broken up into functions that perform specific tasks.

A function that tests an argument and returns a true or false value would return a.....

bool or boolean value.

Exit( ) function

causes a program to terminate regardless of which function o control mechanism is executing.

//Label the function.... int main () { cout << "Hello World" endl; return 0; }

int is return type main is funtion name ( ) is parameter list(which is empty) cout << "Hello World" endl; retur 0 is Function Body.

Parameter list(function)

A list of variables that hold the values being passed to the function.

Is it possible to return multiple values from a function?

But they must be "packaged" in such a way that they are treated as a single value.

Return statement

Causes function to end immediately

Can you have two local variables with the same name?

NO

Code Reuse

The benefit of using functions where it can be written once to perform a task and then be executed anytime it is needed.

Functions that return a value are known as.....

Value-returning functions

Local variable

A local variable is defined indside a function and is not accessible outside the function. They are hidden from the statements in other functions.

Global variable

Any variable defined outside all the functions in a program. The scope of a global variable is the portion of the program from the variable definition to the end. A global variable can be accessed by all functions that are defined after the global variable defined.

Void Functions

Functions that don't return a value. And simply perform one or more statements, which follows terminate.

Function definitions have the following parts....

Return type, Name, Parameter list, Body.

Return type(function)

The data type of the value that is sent from the function. A function can send a value to the part of the program that executed it.

Name(function)

The same rules that apply to variable names also apply to function names.

Can you have a local or parameter variable with the same name as a global variable or constant?

Yes

stubs

a dummy function that is called instead of the actual function it represents.

When used as parameters, reference variables allow....

a function to access the parameter's original argument.

driver

a program that tests a function by simply calling it

A function is executed when it is......

called.Function main is called automatically when a program starts, but all other functions must be executed by function call statements.

When writing a function you must write its....

definition.

When a reference parameters is used....

it is said that the argument is passed by reference.

Variables that are defined inside a function are called......

local variables.

Problem's with global variables....

makes debugging diffuicult. Functions that use global variables are usually dependent on those variables. Global variables make a program hard to understand.

Unless you explicitly initialize numeric global variables.....

they are automatically initialized to zero. Global character variables are initialized to NULL

an example of a void function.....

//The return type of this function is void. Which means the function //does not return a value to the part of the program that executed //it.Also the function has no return statement. void displayMessage( ) { cout << "Hello from the function displayMessage.\n"; }

A value returning function must have a return statement written in this format:

//expression is the value to be returned. return expression;

Body(function)

The set of statements that perform the function's operation. They are enclosed in a set of braces.

Shadows

The shared name of local and global variables.

default arguments

arguments that are passed to the parameter when the actual argument is left out of the function call.

Global variable

defined outside all functions and is accessible to all functions in its scope.

The lifetime of a local variable

how a local variable exist only while the function is executing. So any value stored in a local variable is lost between calls to the function.

If you pass an argument whose type is not the same as....

the parameter's type, the argument will be promoted or demoted automatically.

Overloading functions

this allows you to assign the same name to multiple functions, as long as their parameter lists are different.

static

what you make a variable when you want a program to remember what value is stored in a local variable between function calls. They are not destroyed when a function returns.


Related study sets

Lesson 17: Skeletal - Flexion & Extension

View Set

BIO 1308 (Cell membrane/Transport)

View Set

Principles of Management Exam #1 (CH.1-5)

View Set

Chapter 4: Life in Medieval Towns

View Set

Ch. 2 - Structure of Archaeological Inquiry (ANT 213)

View Set

CHEM1212 Final exam (EXP 9 - EXP 20)

View Set

System Analysis and Design Final

View Set