Where is a global variable normally declared in a C++ program?

Options

  • A. Inside a loop only
  • B. Inside a function only
  • C. Outside all functions
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. Outside all functions

Detailed Explanation

Answer: (C) Outside all functions

A global variable is normally declared outside all functions. Its scope can extend across multiple functions in the same source file, subject to the rules of linkage and visibility.

For example:

int count = 0;

int main() { ... }

Here, count is declared outside main(), so it is a global-scope variable.