+ 2
Anyone who could explain me what this "cout << (n<m?n:m);" does
the main question is about "?" and ":".
5 ответов
+ 6
its terniary operator to use in place of if/else
+ 5
this is short hand of if thn els
(condin)?(true code):(falsecode)
(m>n)?cout<<"greater":cout<<"small";
if(m>n)
codes here tru;
else
codes here fals;
+ 2
analising the content of parenthesis (...) the first condition is a if statement, after the char "?" are the answers separated by ":", in the order: if true the first and if false the second.
cout will print the answer.
+ 2
If n<m evaluates to true, then n will be outputted to cout, else m.
This is your classic ternary statement - the "?" specified the condition to be evaluated and the ":" separates the result if true (left side) from if false (right side).
It is shorthand for if(..).. else ..
+ 2
thanks guys