+ 6

why the resulte is equal to 2 //Like it if u love it

#include <iostream> using namespace std; int main() { int i=true; int j=false; if (i!=j){ cout << (++i); }else{ cout << (i); } return 0; }

10th Feb 2017, 2:04 PM
L Boudhar
L Boudhar - avatar
2 odpowiedzi
+ 5
because i is equal to 1 and j is equal to 0 i is diffident to j then i is incremented by 1
10th Feb 2017, 2:06 PM
L Boudhar
L Boudhar - avatar
0
The result is two because you are specifying the variable types as 'int'. Because you are doing that, i = 1, and j = 0. (1 being the integer "equivalent" of true, and 0 for false.) Then, you test if i is not equal to j, which it is, so then you output 2. You are outputting 2 because you are incrementing i before the variable name. (++i = 2) If you were to type i++, you would be outputting 1.
10th Feb 2017, 2:09 PM
SpecialEffectz