+ 1
Output
Int I=3; If(!I) I++; I++; If(I==3) I+=2; I+=2; Printf("%d", I); The output is 6 but how?
7 ответов
+ 4
Lets format your code to understand more easily:
int l = 3;
if (!l) { // False. Doesn't execute.
l++;
}
l++; // l = 4
if (l==3) { //Doesnt execute either cause l=4 now.
l += 2;
}
l += 2; // 4 + 2
printf( %d", l);
See? When you doesn't use brackets for an if, else, for, while etc..., Only the [ONE] instruction immediately after it gets executed.
First you assign 3 to l. Then you check if l doesn't has a Truthy value, which is true because e is a true value, and the ! operator inverts the result which returns false to the if test. Then you increment by one and checke if l == 3, which is false cause at that point l is equal to 4, so it skips the if block and executes the last statement: l += 2.
4 + 2 = 6.
+ 2
Achintya Raj
Here i is declared so !i will be false and if condition will not work only one i++ will work.
So here i will be 4
Now again i == 3 will be false so Only one i += 2 will work and i will be 6
+ 1
Achintya Raj First i is 3 then it is increment & you add 2 then it becomes 6
+ 1
But what is the reason
+ 1
Thanks
0
Such an easy question I didn't recognise
0
Thanks for the ans