Which statement about a function parameter in C++ is correct?

Options

  • A. It is accessible throughout the whole program
  • B. It has scope within the function where it is defined
  • C. It must always be a global variable
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. It has scope within the function where it is defined

Detailed Explanation

Answer: (B) It has scope within the function where it is defined

A function parameter behaves like a local variable with respect to its scope. It can be accessed within the function body where the parameter is declared.

For example:

void add(int a, int b) { int sum = a + b; }

Here, a and b are parameters and are available within the function body.

They are not global variables and cannot normally be accessed directly from another unrelated function.