- 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
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
+ 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;
0
Programm Doesn't run actually. By the way 3, is the right answer sure?