what is difference between unary operator and binary operator in c++ programming?


3 Answers

Lia Tan Profile
Lia Tan answered

A unary operator operates on a single operand while a binary operator operates on a two operands.

For instance, a unary minus simply makes the operand negative. For example, if your operand is 5, a unary minus will make it -5. A binary minus operates on two different operands, subtracting one from another. So if the two operands are 5 and 3, applying a binary minus will result in 5-3 = 2.

Florio Potter Profile
Florio Potter answered

Unary '-' : It is used with a single operand and that is why it is an unary operator.Binary '-' : This operator functions upon two operands and returns the difference between the two by subtracting the value of second operand from the first. Both the operands may have float or integer types.

For more information get help at CodeAvail- Online Computer Science Assignment

Taila Nevado Profile
Taila Nevado answered

One of the main differences between these two is
that one operand is needed for unary operators and binary operator is dependent
on two operands. Here is a link where you will find additional information
related to this topic. I hope that my answer is
useful to you. See you soon. J

Answer Question