+ 3

What is happening on line printf plzz explain

https://code.sololearn.com/cCqfUTr9gizP/?ref=app

27th Apr 2018, 6:07 PM
Arman khosla
Arman khosla - avatar
5 Antworten
+ 9
Arman khosla in C and C++, 1 = true, 0 = false. For i=1, 1%2 = 1, hence true and i is printed (1). For i=2, 2%2 = 0, hence false and i*2 is printed (2*2 =4). For i=3, 3%2 = 1, hence true and i is printed (3). Output: 143
27th Apr 2018, 6:43 PM
Rusty.Metal
+ 10
It's called "ternary" operator. The statement before '?' is the conditon and the 2 values on the left and right are the values to print based on true or false. If the condition is true left is printed, If it's false right is prinred.
27th Apr 2018, 6:17 PM
Rusty.Metal
+ 7
Happy to help, feel free to ask any questions bro Arman khosla .
27th Apr 2018, 6:46 PM
Rusty.Metal
+ 3
? is a short form of if statement, (i%2) ? i : i*2 so the expression before is checked to see if its true or false (in this case it checks if its even) like in a normal if statement, the first expression will happen if its true (1+ which in this case would be odd) so the program prints i untouched, second one after the colon (:) is the expression that will happen if the program is false (0), so if the number is even it will be doubled
27th Apr 2018, 6:17 PM
TurtleShell
TurtleShell - avatar
+ 2
ooh thank you bro i understood😃
27th Apr 2018, 6:45 PM
Arman khosla
Arman khosla - avatar