Definitions Some C++ operators

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 25
Reputation: konyango is an unknown quantity at this point 
Solved Threads: 0
konyango's Avatar
konyango konyango is offline Offline
Light Poster

Definitions Some C++ operators

 
0
  #1
Jun 26th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 132
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster

Re: Definitions Some C++ operators

 
0
  #2
Jun 26th, 2009
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:
  1. a * b // binary
  2. true && false // binary
  3. -1 // unary
  4. !x // unary
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 57
Reputation: emarshah is an unknown quantity at this point 
Solved Threads: 5
emarshah emarshah is offline Offline
Junior Poster in Training

Re: Definitions Some C++ operators

 
0
  #3
Jun 26th, 2009
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

  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

  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.
Syed Ammar Hassan
" A man is known by his level of Determinism "
--------------------------------------------------------
"Some cause happiness where ever they go, others whenever They go"
--------------------------XIII---------------------------
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 25
Reputation: konyango is an unknown quantity at this point 
Solved Threads: 0
konyango's Avatar
konyango konyango is offline Offline
Light Poster

Re: Definitions Some C++ operators

 
0
  #4
Jun 27th, 2009
Thank you very much guys !!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC