Multiple choice technology programming languages

In namespace foo, the function bar can access the variable x also declared in namespace foo? #include namespace foo { void bar() { x++; } int x; } int main(int argc, char** argv) { return 0; }

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In C++, name lookup is sequential. At the point of x++ in bar(), x has not yet been declared in the namespace. Thus, name lookup fails, and bar() cannot access x without a forward declaration or declaring x first.