Quick question, is it good practice to initialize all “blank or empty” variables when it has not to carry either positive or negative values, for example using this:
int value = 0;
instead of:
int value;
I accept the Visual Studio compiler, from what I understand, automatically initializes variables to 0 by default if they are not initialized before hand but I am curious as to what the best practice is and what the potential hazards (if any) are.
Although I am referring to the C# and C++ languages within the VS environment particularly, this question is open to any languages and compilers across the spectrum.
It is always good practice to initialize variables to prevent undefined behavior later in the program. Some later compilers might do this for you, but at the lower lever not defining a variable CANNOT be caught by the compiler and can lead to some very painful headaches. If you have a massive list of variable i usually use a big equals statement:
it’s apart of the bigger c++ philosophy to always have a value stored in your variable at all times .