943,625 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 525
  • C++ RSS
Jun 26th, 2009
0

Definitions Some C++ operators

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
coachHinesfan is offline Offline
32 posts
since Oct 2008
Jun 26th, 2009
0

Re: Definitions Some C++ operators

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:
C++ Syntax (Toggle Plain Text)
  1. a * b // binary
  2. true && false // binary
  3. -1 // unary
  4. !x // unary
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009
Jun 26th, 2009
0

Re: Definitions Some C++ operators

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

C++ Syntax (Toggle Plain Text)
  1.  
  2. int result =0 , op1 = 3, op2= 4;
  3.  
  4. result = op1 + op2;
  5.  
  6. // the value of result will be 7 because '+' is a binary operator
  7. // 'op1' and 'op2' are the two operands

while in the case of unary operator

C++ Syntax (Toggle Plain Text)
  1.  
  2. int op1 = 10;
  3.  
  4. op1++;
  5.  
  6. // now the value of op1 is 11, because '++' is a unary operator
  7. // it involves only one operator, it adds a 1 to the 'op1' and put
  8. // that result back into 'op1'
Last edited by emarshah; Jun 26th, 2009 at 4:59 pm.
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
emarshah is offline Offline
61 posts
since Jan 2008
Jun 27th, 2009
0

Re: Definitions Some C++ operators

Thank you very much guys !!
Reputation Points: 10
Solved Threads: 0
Light Poster
coachHinesfan is offline Offline
32 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: push_back keeps reseting vector[0]! And it's really annoying !
Next Thread in C++ Forum Timeline: Seriously? Windows Winnie Tute





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC