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.
3 Antworten
+ 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.
+ 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
0
see it like this if you put:
a=100
a=50
then the last one in that INT wil be printed out