Comp 121

Chapter 6 Study Guide

Chapter 6

 

How do you call and pass data to a function?

 

What is a called function and what is a calling function?

 

What is a function prototype and what does it tell the calling function? What is the general form of the function prototype?

 

For the following function prototypes, what are the return-data-types?

int fmax(int, int)

void display(double, double)

double foo(void)

 

What are a function’s arguments?

 

Describe the procedure for passing data to a function? (For example, does the function receive a copy of the data or the actual data to use, why?)

 

What is the general format of a function?

 

What goes in the body of the function?

 

What is the general rule for the placement of statements in a C++ program?

 

How are functions with an empty parameter list declared?

 

How are default arguments used? Why are they useful?

 

How can you write a single, complete function that can serve as a model for a family of functions? For example, you want one function abs that can be passed an int, a double, or a float as its argument.

 

Can templates be used to choose the return type of a function? Why is this useful?

 

What is function overloading? How does the compiler know which function to use if a function is overloaded?

 

When a single value is being returned by a function, what must the called function provide? How does it do this?

 

After a value is returned, where does program control go?

 

What will happen if the value being returned by a function is a different data type then the function’s declared data type?

 

What must the calling function (receiving side) take care of when a value is returned?

 

What must the program do to actually use a returned value?

 

What overhead does a computer have when a function is called? What is an inline function and why is it useful?

 

How is data passed when it is passed by value? Why is it useful? What is a pass by reference? When would it be used over pass by value?

 

How is a reference parameter declared in C++? What information does it store? What does the symbol & mean in C++?

 

What is the algorithm to exchange (or swap) values in two variables?

 

What is a local variable? What is its scope? How is a variable with local scope different from a variable with global scope?

 

Why is it bad programming to use only global variables?

 

What are the four available storage classes for a variable? Which classes can local variables be members of?

 

Which storage class allows the program to keep the variable and its latest value even when the function that declared it is finished executing? How many times are these variables initialized?

 

Which two storage classes can a global variable NOT be? Why?

 

What does the extern storage class do?