Differentiate between a unary, a binary and a ternary operator. Give examples of C++ Operators for each one of them.
Answers
Answered by
73
In C programming language, unary, binary &ternary operators are useful for carrying out mathematical operations.
- Unary operators are those that work on single operand e.g. increment operator( ++) or the decrement operator( - - ). int a =b++; or something like int C =d- -;
- Binary operators are the one that operate on two operands e.g. ‘+’, ‘ -’, ‘ *’, ‘/’. Syntax can be like int C=a+b;
- Ternary operators are the one that operates on three operands. It takes three argumets . 1st argument is checked for its validity . If it is true 2nd argument is returned else third argument is returned. For example if we write int C= a>b ? e:f; now if a is greater than b 'e' is returned otherwise 'f' is returned.
Answered by
3
Answer:
Ans. A unary operator requires a single operand. unary+, unary-, ++, –, sizeof etc. are some unary operators in C++.
A binary operator requires two operands.
+(add), -(subtract), *, /, % etc. are some binary operators in C++.
A ternary operator requires three operands. ?: (the conditional operator) is a ternary operator in C++.
Explanation:
thanks
Similar questions