int a=100; a=50;. cout<<a;. //Outputs 50. I' m confused that how it is possible. | Sololearn: Learn to code for FREE!
0

int a=100; a=50;. cout<<a;. //Outputs 50. I' m confused that how it is possible.

The "a" is assigned two values but it is giving output only for one value that is 50.

22nd Mar 2017, 11:18 AM
Jar Vis
Jar Vis - avatar
3 Answers
+ 16
Your 'a' is a variable. This means that it is subjected to change. When we do: int a = 100; a = 50; We are altering the value from 100 to 50, instead of assigning another value to the variable. Any variable can only hold a single value at one instance.
22nd Mar 2017, 11:23 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
initially a was assigned 100 but in next step you yourself updated it to 50 so now a holds a value of 50…, that is why it prints 50
22nd Mar 2017, 1:17 PM
Ritveak Dugar
Ritveak Dugar - avatar
0
see it like this if you put: a=100 a=50 then the last one in that INT wil be printed out
27th Mar 2017, 2:47 PM
Rick Jonkman
Rick Jonkman - avatar