What will be the output of the following C++ code? [code] #include <iostream> using namespace std; int main () {

What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    int main ()
    {
        int a, b, c;
        a = 2;
        b = 7;
        c = (a > b) ? a : b;
        cout << c;
        return 0;
    }
A. 2
B. 7
C. 9
D. 14
 
Answer: b
Explanation: We are using the ternary operator to evaluate this expression. It will return first option, if first condition is true otherwise it will return second
Output:
Code:
$ g++ ess1.cpp
$ a.out
7
 

Tìm kiếm

Back
Top