+ 4
Why we should give some value to a variable?
is it neccesary?
2 Answers
+ 6
No, you can make an empty var.
+ 3
If you don't initialize a local variable, it can contain anything, i.e. it won't be assigned a standard value. Thus, reading and using an uninitialized variable can cause undefined behavior of your program.
That's why it's best practice to initialze them, e.g. always setting them to 0. So in that case, you can always be sure that they have a certain value right from the beginning.