C++ Quiz10 of 173
Difficulty:
⬅️ Prev: 9Quiz ID: 11Next: 12 ➡️

According to the C++23 standard, what is the output of this program?

#include <iostream>

int a;

int main () {
    std::cout << a;
}
Hint

Is a static? And what do we mean by "static" anyway? Think about the difference between static storage duration and external linkage.

Reveal answer

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 inside main(), 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.

⬅️ Prev: 9Quiz ID: 11Next: 12 ➡️