- 3

#include using std::cout; int main() { int i=0;     cout << (i=0? 1:2? 3:4);    return 0;    }

What is the output? A)3 B)2 C)1

14th May 2020, 11:31 PM
Md Saiful Islam
Md Saiful Islam - avatar
3 Respostas
+ 2
You can use code playground to check what is the output ,click on your profile ,there you will see code bits ,click on + sign and choose a language , The answer for this should be 3 it is like 0?1:2 0 means False and second value is choosen which is 2 now in 0?1:2?3:4 any value which is 1 and greater than 1 means true so 3 is choosen I am assuming you know how ternary operators work
14th May 2020, 11:37 PM
Abhay
Abhay - avatar
+ 2
That code will produce an error, but if this is what you meant; #include <iostream> using namespace std; int main() { int i=0; cout << (i=0? 1:2? 3:4); return 0; } Then 3 Look up the ternary operator. https://www.cprogramming.com/reference/operators/ternary-operator.html condition ? true case : false case;
14th May 2020, 11:43 PM
ChaoticDawg
ChaoticDawg - avatar
0
Programm Doesn't run actually. By the way 3, is the right answer sure?
14th May 2020, 11:39 PM
Md Saiful Islam
Md Saiful Islam - avatar