Distinguish between a unary, a binary and a ternary operator.

Q1. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

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++.

Leave a Reply

Your email address will not be published. Required fields are marked *

75 Views
%d bloggers like this: