+ 3
What is happening on line printf plzz explain
5 Réponses
+ 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
+ 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.
+ 7
Happy to help, feel free to ask any questions bro Arman khosla .
+ 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
+ 2
ooh thank you bro i understood😃