0

Why is the output of this code 6? I feel like it should give a error .

25th Nov 2020, 5:08 AM
Kyoden
Kyoden - avatar
4 Answers
+ 4
a = 8 b = ++a, so both a and b are 9 now if (a>5) is true b -= 3 which is 9-3=6 So else is not executed and value of b is printed to the console.
25th Nov 2020, 5:19 AM
Avinesh
Avinesh - avatar
+ 2
If the c for console is lowercase, then yes it will give an error. Otherwise, 6 is the correct output. b is set to ++a which is 9 a > 5 is true so b -= 3 is ran. Now b = 6 which is then output.
25th Nov 2020, 5:21 AM
ChaoticDawg
ChaoticDawg - avatar
0
int a = 8; int b = ++a; if (a > 5) b -= 3; else b = 9; console.WriteLine(b);
25th Nov 2020, 5:09 AM
Kyoden
Kyoden - avatar
0
I see, thanks this dose answer some questions
25th Nov 2020, 5:21 AM
Kyoden
Kyoden - avatar