What will be printed on the screen?
//file1.cpp
extern const int a = 77;

//file2.cpp
#include <iostream>
using namespace std;
extern const int a;

void f() {
    cout << a << endl;
}
Explanation
The extern keyword tells the compiler that a variable is declared in another source module (outside of the current scope).
The correct answer: 77, by default const implies an internal scope, so if we had a declaration in both files without extern, there would be a compilation error - "in file2.cpp a constant without initialization is declared".
extern makes the constant scope externally visible - so the value a = 77.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести