Why is this so when "res" is the type of value, and by default it should be 0?
Although the default value is 0 in member fields, locals require an explicit value setting. The compiler will warn you that you are using it without initializing it, as this may be a mistake.
Although it can be “technically” fine with a zero initialized default value from a logical point of view, from a real point of view, the fact that you never set the value before checking it is either 1) useless ( if will never be true) or 2 ) error (you wanted to set the value, but something has changed).
In any case, a warning should help you prevent an accident.
I must indicate that if I specifically set the res value to 0, then everything is OK.
When you do this, you specifically provide a value, so the compiler no longer warns you.
source share