C++: Functions

Ace your homework & exams now with Quizwiz!

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

when it encounters a return. It requires a return statement when it reaches the closing brace

Void function?

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.

What is pass by reference and how is it done?

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

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

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.

Function Overloading? How is it done?

Functions can have the same name and type but must have a different parameter listing. EX: int function (int); int function (int, int);

How are default arguments applied to a function?

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.

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

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.

Local Variables inside a function ______

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

What is the difference between parameters and arguments?

Parameter: void function (var1, var2, var3) <-- parameter Argument: function(1, 2, 3) <-- argument Parameters set up values to be sent to function. Arguments are the values sent to the function.

A function is identified by?

Parenthesis ().

How is the round function used?

Requires < cmath > header Accepts a value and returns an int rounded to the nearest whole number. EX: cout << round(25.5); will output 26.

What is the exit function?

Requires: < cstdlib > will terminate the program wherever it is used. exit(0);

return 0; in the main function does what?

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

Static variables? How are they used?

Static variables keep their values from a function through multiple calls to the program. static int variable;

Body of function

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

Prototype? What is the format?

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);

Function Definition

The header and body of the function.

Return type?

The type of data that the function returns upon completion int doStuff() int is the return type.

Pass by value?

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.

Every c++ program must have 1 ______ function?

main

A bool function can return

only true or false. The definition of the bool type.

How can a function return an expression?

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

Function call

simply using the function in your program.


Related study sets

Chapter 14: Direct and Online Marketing

View Set

3303 Fundamental Lecture Mastery Level Question Chapters 19, 24

View Set