+ 4

Why we should give some value to a variable?

is it neccesary?

21st Dec 2016, 5:36 PM
mahesh naandade
mahesh naandade - avatar
2 Answers
+ 6
No, you can make an empty var.
21st Dec 2016, 5:37 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 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.
21st Dec 2016, 10:22 PM
alex189