0

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.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by coachHinesfan
0

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
0

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'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.