Computer Science, asked by nguniquenikhil5303, 1 year ago

Differentiate between a unary, a binary and a ternary operator. Give examples of C++ Operators for each one of them.

Answers

Answered by Anonymous
73

In C programming language, unary, binary &ternary operators are useful for carrying out mathematical operations.

  1. 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- -;
  2. Binary operators are the one that operate on two operands e.g. ‘+’, ‘ -’, ‘ *’, ‘/’. Syntax can be like int C=a+b;
  3. 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 roshni31mondal
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