What is the scope of the variable declared in a user-defined function?

Options

  • A. Whole program
  • B. Only inside the { } block
  • C. Inside the main function
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. Only inside the { } block

Detailed Explanation

Answer: (B) Only inside the { } block

A variable declared inside a user-defined function is a local variable. Its scope is limited to the block in which it is declared.

For example, if a variable is declared inside a function, it cannot normally be accessed directly from another function.

Therefore, its scope is not the whole program and it is not limited specifically to the main() function. It belongs to the block in which it is declared.