functions Flashcards

1
Q

A function is identified by?

A

Parenthesis ().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Prototype? What is the format?

A

The declarative piece of the function. It is used like a variable declaration and comes before main or inside of it.

void function(int x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

return 0; in the main function does what?

A

Returns 0 to the operating system of the program to let it know that the program is done executing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Function call

A

using the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Function Definition

A

The header and body of the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Return type?

A

The type of data that the function returns upon completion

int doStuff()

int is the return type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Body of function

A

The bracket enclosed section of the function that actually performs the objective.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between parameters and arguments?

A
Parameter: 
void function (var1, var2, var3)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Void function?

A

A function of the form:

void function ();

that doesn’t return anything but rather, it simply performs a task. It can take varying parameter types however.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A function with a return type terminates at _____ a void function terminates _____

A

when it encounters a return. It requires a return statement

when it reaches the closing brace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Local Variables inside a function ______

A

Only exist in that function and are lost once the function terminates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the rule for the parameters of your prototype? What about the definition?

A

For the prototype you just need to note what type of parameters you’re using.

For the definition you must note the name of the variable and the type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Pass by value?

A

To pass a function a variable to operate with. This variable is a copy of the original and is terminated once it returns to main. Meaning the original value is unchanged in main.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the accessibility of local and global variables to functions?

A

Local variables are only accessible to the functions they are defined in. Local variables can have the same name inside their respective functions.

Global variables are accessible to all functions since they are defined outside all functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Static variables? How are they used?

A

Static variables keep their values from a function through multiple calls to the program.

static int variable;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Every c++ program must have 1 ______ function?

A

main

17
Q

How are default arguments applied to a function?

A

In the prototype just assign the data type a value. The default values must come after those that do not have defaults.

EX:

int function (int = 5, double = 1.2); 
or: int function(int num = 5, double num = 1.2); 

when called, the function defaults to those values and any entered parameters can overwrite the defaults.

18
Q

What is pass by reference and how is it done?

A

A pass by reference allows a function to change the original value of a variable passed to it from inside the function.

Ex: int dostuff (int &variable)

variable can now be changed from dostuff

19
Q

Function Overloading? How is it done?

A

Functions can have the same name and type but must have a different parameter listing.

EX:

int function (int); 
int function (int, int);
20
Q

How can a function return an expression?

A

return value + value2;
return value / value2;
return value * value;

etc

21
Q

A bool function can return

A

true or false`

22
Q

How is the round function used?

A

Requires < cmath > header

Accepts a value and returns an int rounded to the nearest whole number.
EX:

cout &laquo_space;round(25.5);

will output 26.

23
Q

What is the exit function?

A

Requires: < cstdlib >

will terminate the program wherever it is used.

exit(0);

24
Q

test driver

A

like main

this runs the function

25
Q

functional decompositon

A

breaks the function down

26
Q

pass by reference in a function

A

add a & after the data type