answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why ternary operator is not overloaded?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are special operators in c plus plus?

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().


How can you differentiate overloading of pre-fix and post-fix increment operator?

The prefix increment operator is overloaded as operator++() while the postfix increment operator is overloaded as operator++(int).


What are the disadvantages of scope resolution operator?

it cannot be operator overloaded.


How do you find the greatest of three numbers using ternery operator?

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.


Which operator is called ternary operator?

A ternary operator is an operator that requires three operands, as opposed to a binary operator that requires two operands and a unary operator that requires just one operand. C++ has just one ternary operator, the conditional ternary operator: <boolean expression> ? <expression #1> : <expression #2>; If the boolean expression evaluates true, the first expression is evaluated, otherwise the second expression is evaluated. A typical usage of this operator is to return the larger (or smaller) of two values of type T: template<typename T> T max (T a, T b) {return a<b ? b : a}; template<typename T> T min (T a, T b) {return a<b ? a : b}; These are really nothing more than notational shorthand for the following: template<typename T> T max (T a, T b) {if (a<b) return b; else return a; }; template<typename T> T min (T a, T b) {if (a<b) return a; else return b;}; However, because ternary expressions are evaluated, the return value of the expression can be used in more complex expressions: int a=42, b=0; // ... int c = ((a>b ? a : b) = 1); In the above expression, whichever is the larger of a and b will be assigned the value 1 which will also be assigned to c. Thus a and c become 1 while b remains 0.

Related questions

Which c plus plus operators cannot be overloaded?

1. Member-of operator (.) 2. Pointer-to-member-of operator (.*) 3. Ternary condition operator (?:) 4. Scope resolution operator (::) 5. sizeof operator 6. typeid operator


What are special operators in c plus plus?

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().


How can you differentiate overloading of pre-fix and post-fix increment operator?

The prefix increment operator is overloaded as operator++() while the postfix increment operator is overloaded as operator++(int).


What are the disadvantages of scope resolution operator?

it cannot be operator overloaded.


How do you find the greatest of three numbers using ternery operator?

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.


What is condional operator?

Conditional Operator- Its the only ternary operator in c/c++.- Its syntax is-(condition)?statement1:statement2;-Shruti Jain


What is the name of the expression that is formed by using logical operators?

Ternary operator


Which operator is called ternary operator?

A ternary operator is an operator that requires three operands, as opposed to a binary operator that requires two operands and a unary operator that requires just one operand. C++ has just one ternary operator, the conditional ternary operator: <boolean expression> ? <expression #1> : <expression #2>; If the boolean expression evaluates true, the first expression is evaluated, otherwise the second expression is evaluated. A typical usage of this operator is to return the larger (or smaller) of two values of type T: template<typename T> T max (T a, T b) {return a<b ? b : a}; template<typename T> T min (T a, T b) {return a<b ? a : b}; These are really nothing more than notational shorthand for the following: template<typename T> T max (T a, T b) {if (a<b) return b; else return a; }; template<typename T> T min (T a, T b) {if (a<b) return a; else return b;}; However, because ternary expressions are evaluated, the return value of the expression can be used in more complex expressions: int a=42, b=0; // ... int c = ((a>b ? a : b) = 1); In the above expression, whichever is the larger of a and b will be assigned the value 1 which will also be assigned to c. Thus a and c become 1 while b remains 0.


What is the operator that cannot be overloaded?

There are 5 operators which cannot be overloaded. They are: * .* - class member access operator * :: - scope resolution operator * . - dot operator * ?:: - conditional operator * Sizeof() - operator Note:- This is possible only in C++.


What is the operator that cannot be overloaded in c plus plus and java?

conditional operator , size of operator , membership operator and scope resulation operator can not be overload in c++


Can the scope resolution operator be overloaded in C plus plus?

No.


How can you download c compiler?

write a c program to fine largest/smallest of 3no (using ?:ternary operator/conditional operator)