C++ Interview Question 10 Answer

Bjarne-stroustrup
 

Answer

This question is compilable and deterministic.

Its output is “0”.

Explanation

Since a has static storage duration and no initializer, it is guaranteed to be zero-initialized. Had a been defined as a local non-static variable insidemain(), this would not have happened.

Note: int a has static storage duration because it is declared at namespace scope. It does not need to have static in front of it, that would only denote internal linkage.

SOURCE