+ 1
Why does the output of int a = 100; a = 50; cout << a; come out with 50 instead of 100?
I'm just a little confused
5 ответов
+ 1
because your a = 50 when you declare
int a = 100 then a = 100
and then
a = 50 then a become 50
that is why a = 50
+ 1
Because the code executes top-bottom direction, so it first define int a with inicial value of 100, then redefines it with a=50, keeping that last value dor output
+ 1
You overwrite a variable. Compiler reads one line in time, so first it finds out that a = 100, but then it changed to 50. So, here you are
0
thanks. that's been stuck in my head for a while.
0
because first the value is initialized for 'a' but then a new value is assigned to 'a'. Since the print statement is used after the assignment of new value the output comes out to be 50.