0

Is there any difference between writing:

1) int x = 5; And 2) int x; x = 5;

26th Apr 2017, 12:49 PM
Tina
3 Answers
+ 29
the same result, but first looks better. @Pixie shouldn't D+I be in first var?
26th Apr 2017, 12:58 PM
Illusive Man
Illusive Man - avatar
+ 12
Both are same 2)is Declaration and Initialisation done separately. 1)is Declaration+Initialisation
26th Apr 2017, 12:51 PM
Pixie
Pixie - avatar
+ 2
The first way sets the value of the variable immediately and the second way sets it in the next line. If you do the second way then always make sure that you set a value to the variable, like you did in the second line, else the variable won't have a value and will give you an error.
26th Apr 2017, 12:58 PM
Ghauth Christians
Ghauth Christians - avatar