+ 1

Please Explain reason why output is Zero

I don't get why o/p 0. Please explain see answer for code I am talking about

3rd Aug 2017, 12:03 PM
Aditya
Aditya - avatar
5 Answers
+ 9
a=a; b=b; is ambiguous. The compiler reacted by assigning the value of the variables back to themselves instead of assigning the parameters to the local variables in class Program. Fix this by simple renaming the parameters. E.g. Program(int x, int y) { a = x; b = y; }
3rd Aug 2017, 12:16 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
Ah, yes. I missed that. 'this' would be able to specify which variable to use.
3rd Aug 2017, 12:18 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Thanks Hatsy. It seems we can use *this* keyword too.
3rd Aug 2017, 12:17 PM
Aditya
Aditya - avatar
0
This is because there is no input bull the user nor the values of the variables initialized Hence,the out put is zero the comp. takes a as 0 as well as b 0 therefore sum is 0
3rd Aug 2017, 12:19 PM
Adhiraj Dhar
Adhiraj Dhar - avatar