+ 2

explain

int x=(5+8)/10; if(x) cout << "10"; else cout << "20"; //what should be answer

18th Jul 2017, 1:15 PM
‎ ‏‏‎Anonymous Guy
4 Answers
+ 11
Declaring an integer variable named x and assigning it a value of (5+8) or 13/10 i.e., 1. The program takes 1 as true. As the if statement checks the condition and then executes the block of code if the result is true otherwise not if false. So, the first statement results in true giving 10 as the output. Note : If the condition had been false or 0, then the else statement would be executed and not the if one.
18th Jul 2017, 1:41 PM
Dev
Dev - avatar
+ 11
@Sreejith : Then maybe the quiz was wrong. Please if you again come through any wrong questions in challenges, report them immediately :]
18th Jul 2017, 4:50 PM
Dev
Dev - avatar
+ 2
ok thanks
18th Jul 2017, 4:53 PM
‎ ‏‏‎Anonymous Guy
+ 1
it was In challenge and answer was 20
18th Jul 2017, 4:49 PM
‎ ‏‏‎Anonymous Guy