R = (A > B && A > C) ? A : (B > C) ? B : C; // parentheses not necessary - for clarity only
max = a > b ? a : b; max = max > c ? max : c;
Ternary operator
write a c program to fine largest/smallest of 3no (using ?:ternary operator/conditional operator)
// assume you want the find the largest of ints a,b,c: int max = (a>b&&a>c?a:b>c?b:c);
int max (int a, int b) { return a<b?b:a; } int max3 (int a, int b, int c) { return max (max (a, b), c); }
0 1 and 2
All numbers - integers as well as non-integers - are combined using different mathematical operations. Some operators are binary: that is, they combine two numbers to produce a third; some are ternary (combine 3 to produce a fourth) and so on.The set of integers is closed under some operations: common examples are addition, subtraction, multiplication, exponentiation. But not all operators are: division, for example.
Maybe your speaking a variable that contains a ternary operators such as:
The only "special" operators in C++ are those that cannot be overloaded. That is; the dot member operator (.), pointer to member operator (.*), ternary conditional operator (:?), scope resolution operator (::), sizeof() and typeof().
Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.
The answer depends on what you are converting from: binary, ternary, octal, hexadecimal ...
The ternary operator (known as the conditional operator in C++) cannot be overloaded because it is impossible to pass a test operand and two expression operands (either or both of which may be comma-separated) to a function. You can only pass values or references as arguments to a function. Even if it were possible, built-in functions and operators that rely on the conditional operator would likely break. Like all the other operators that cannot be overloaded (sizeof, typeid, ::, . and .*) the results must always be predictable because built-in operators and functions rely on them so heavily.