Answers 827
D
- Scope refers to the visibility and lifetime of local and global variables. Scope is
usually established by a set of braces. - Recursion generally refers to the ability of a function to call itself.
- Global variables are typically used when many functions need access to the same
data. Global variables are very rare in C++; after you know how to create static
class variables, you will almost never create global variables. - Function overloading is the ability to write more than one function with the same
name, distinguished by the number or type of the parameters.
Exercises ........................................................................................................
1.unsigned long int Perimeter(unsigned short int, unsigned short int);
- The following is one possible answer:
unsigned long int Perimeter(unsigned short int length, unsigned short int
➥width)
{
return (2length) + (2width);
} - The function tries to return a value even though it is declared to return voidand,
thus, cannot return a value. - The function would be fine, but there is a semicolon at the end of the myFunc()
function’s definition header. - The following is one possible answer:
short int Divider(unsigned short int valOne, unsigned short int valTwo)
{
if (valTwo == 0)
return -1;
else
return valOne / valTwo;
} - The following is one possible solution:
1: #include
2: using namespace std;
3:
4: short int Divider(
5: unsigned short int valone,
6: unsigned short int valtwo);
7:
8: int main()
9: {
10: unsigned short int one, two;
11: short int answer;
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 827