In principle, a variable defined outside any function (that is, global, namespace, and class static variables) is initialized before main()
is invoked. Such nonlocal variables in a translation unit are initialized in their declaration order
Above are the lines from the class notes given by my lecturer.
#include <iostream>
using namespace std;
int a=99;
int main(int argc, char *argv[])
{
cout<<a<<endl;
cout<<b<<endl;
return 0;
}
int b=100;
There is an error while I run this. Isn't it true that b
assigned to 100
before main()
is called?