Hello all. I have been reading / practising c++ and through the course of my journey I have been encountering some phrases that I don't understand. The phrases are :

-> Binary operators
-> Unary operators

I have tried to search on google and also on other posts in the forum but I just keep finding them used but I don't understand what exactly they do. I am simply looking for a definition of these terms. Your help will be appreciated.
Thank You.

Recommended Answers

All 3 Replies

A binary operator is an operator like + or / that have two operands, one on each side. A unary operator is an operator that only has one operand:

a * b // binary
true && false // binary
-1 // unary
!x // unary

Hi,
Binary means having two operands for doing the operation
while unary have only one operand to do any operation.

suppose you have the following code for binary operation

int result =0 , op1 = 3, op2= 4;

result = op1 + op2;

// the value of result will be 7 because '+' is a binary operator
// 'op1' and 'op2' are the two operands

while in the case of unary operator

int op1 = 10;

op1++;

// now the value of op1 is 11, because '++' is a unary operator
// it involves only one operator, it adds a 1 to the 'op1' and put
// that result back into 'op1'

Thank you very much guys !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.