I’m writing code in Visual C++ and I need to use a global variable. I know it’s generally not a good idea, but in this case, it is necessary. I have created the variable and it is accessible from the function that needs it, but I can’t figure out how to give it an initial value.
in the .h file it looks like
extern int lversion;
and in the .cpp file it looks like
int lversion;
How can I give this variable an initial value of 0?
The variable does have initial value
0as it is. Globals and statics are value-initialized unless otherwise specified. (for anint, it will be0)If you want any other value, you can specify it:
In the cpp file:
or
but for a value of
0there’s no point being this verbose.