Organizing into Functions 135
5
Quiz ................................................................................................................
- What are the differences between the function prototype and the function
definition? - Do the names of parameters have to agree in the prototype, definition, and call to
the function? - If a function doesn’t return a value, how do you declare the function?
- If you don’t declare a return value, what type of return value is assumed?
- What is a local variable?
- What is scope?
- What is recursion?
- When should you use global variables?
- What is function overloading?
Exercises ........................................................................................................
- Write the prototype for a function named Perimeter(), which returns an unsigned
long intand takes two parameters, both unsigned short ints. - Write the definition of the function Perimeter()as described in Exercise 1. The
two parameters represent the length and width of a rectangle. Have the function
return the perimeter (twice the length plus twice the width). - BUG BUSTERS:What is wrong with the function in the following code?
#include
void myFunc(unsigned short int x);
int main()
{
unsigned short int x, y;
y = myFunc(int);
std::cout << “x: “ << x << “ y: “ << y << “\n”;
return 0;
}
void myFunc(unsigned short int x)
{
return (4*x);
}
4.BUG BUSTERS:What is wrong with the function in the following code?
#include <iostream>
int myFunc(unsigned short int x);
int main()