C++ Function Scope - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
 
1. The function header int foo(int y, int x = 4) means:
  A. y is called by value
  B. x has default value 4
  C. foo returns an int
  D. all of these
  The correct answer is D.
In the header int foo(int y, int x = 4) means that y is called by value, x has default value 4, and foo returns an int.

2. When two functions with the same name are defined in the same scope, the function is:
  A. double
  B. static
  C. overloaded
  D. inline
  The correct answer is C.
Overloading is available in C++, but not in C. It lets the same function name have different definitions.

3. An overloaded function must have:
  A. different return types
  B. different executable statements
  C. different types and/or number of arguments
  D. all of these
  The correct answer is C.
The signature for two overloaded functions must be different. The return type is not part of the signature.

4. To speed up a function make it:
  A. use doubles
  B. static
  C. overloaded
  D. inline
  The correct answer is D.
Inlining a function avoids function call overhead.

5. Only one of the following statements concerning resolving external references in multifile programs is true. Which one is it?
  A. External nonstatic variables must be defined in only one place.
  B. External static variables must be defined in only one place.
  C. Using the keyword extern with an initializer constitutes a declaration.
  D. Using the keyword extern without an initializer constitutes a definition.
  The correct answer is A.
External static variables must be defined in only one place. This is not the case with static variables. The use of the keyword extern with an initializer constitutes a definition. Using extern without an initializer constitutes a declaration.

6. To provide a unique scope similar in effect to the use of static external declarations, use:
  A. a default argument
  B. an inline function
  C. an anonymous namespace
  D. a function prototype
  The correct answer is C.
Anonymous namespaces provide a unique scope similar to the use of static external declarations. The default argument is a formal parameter that is initialized in a function prototype. An inline function is one that is compiled without function call overhead. A function prototype is a function header that lists the types and number of a function's arguments.