Which operator can be used to access a global variable when it is hidden by a local variable with the same name?

Options

  • A. .
  • B. ->
  • C. ::
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. ::

Detailed Explanation

Answer: (C) ::

The scope resolution operator :: can be used to refer to a global variable when a local variable with the same name hides it.

For example:

int x = 100;

void test() { int x = 50; cout << ::x; }

Inside test(), the unqualified name x refers to the local variable. The expression ::x refers to the global variable.