Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default Unary operator and binary operator

    Acc. to the definition a unary operator(+) operates on one operand.

    1. int a=1+1;
    2. int b=+a;

    Now in the line 1 the + operator is used for two operands, while the line 2 operates on one operand. So how can + be called a unary operator or even binary operator, for that matter?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: Unary operator and binary operator

    Those are two different operators that look the same (+); distinguishing between them is a little linguistic problem to be solved by the compiler (blame mathematics for it).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Unary operator and binary operator

    In programming, "+" is defined as the unary plus operator that makes an expression positive (however, numbers are positive without this), e.g int number = +1; however "+=" is assingment operator.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: Unary operator and binary operator

    Quote Originally Posted by allaudin View Post
    In programming, "+" is defined as the unary plus operator that makes an expression positive (however, numbers are positive without this), e.g int number = +1; however "+=" is assingment operator.
    That was not what the OP was asking for and besides, the unary + operator doesn't make the value of the expression positive, e.g. int a= +-3; doesn't make a == 3; stop spewing your incorrect advice in these forums.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default Re: Unary operator and binary operator

    That was not what the OP was asking for and besides, the unary + operator doesn't make the value of the expression positive, e.g. int a= +-3; doesn't make a == 3; stop spewing your incorrect advice in these forums.

    Jos
    that was not my definiton ... Unary Operators and another Unary Operator - Definition for the Term: Unary Operator I already know you will say its wrong but not this time :P
    Last edited by allaudin; 08-27-2013 at 02:30 PM.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: Unary operator and binary operator

    Quote Originally Posted by allaudin View Post
    that was not my definiton ... Unary Operators and another Unary Operator - Definition for the Term: Unary Operator I already know you will say its wrong but not this time :P
    That Rose India site sucks big times; it should be taken off line.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Unary operator and binary operator

    Quote Originally Posted by JosAH View Post
    That Rose India site sucks big times; it should be taken off line.

    Jos
    Full ack!
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,907
    Rep Power
    5

    Default Re: Unary operator and binary operator

    Quote Originally Posted by PhHein View Post
    Full ack!
    Ack ack.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Unary operator and binary operator

    Quote Originally Posted by gimbal2 View Post
    Quote Originally Posted by PhHein View Post
    Full ack!
    Ack ack.
    Ack.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: Unary operator and binary operator

    Quote Originally Posted by allaudin View Post
    that was not my definiton ... Unary Operators and another Unary Operator - Definition for the Term: Unary Operator I already know you will say its wrong but not this time :P
    See? It's not just me who detests that site; and you buntly posted it here as if it were the truth; it's far from it; I'm telling you for the last time (not asking it): stop posting all your nonsense in these forums. You are just a 'sheer beginner' (your own terminology) and not in a position to help out other posters. You merely ruin the threads. You'd better study first before you open your mouth again.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,538
    Rep Power
    5

    Default Re: Unary operator and binary operator

    Interesting! Looks like I got lucky when I chose this site. I haven't checked out Rose India. And looks like I probably won't.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Ace Operator 2.1.0
    By java software in forum Java Software
    Replies: 0
    Last Post: 02-27-2013, 08:51 AM
  2. {} after new operator, what does it mean?
    By willemjav in forum New To Java
    Replies: 3
    Last Post: 01-29-2013, 09:40 AM
  3. Replies: 5
    Last Post: 01-21-2012, 11:02 PM
  4. Binary Operator Methods
    By Keke101 in forum New To Java
    Replies: 8
    Last Post: 01-09-2012, 04:59 AM
  5. What Type is a Binary Operator?
    By TheGame in forum New To Java
    Replies: 5
    Last Post: 10-13-2010, 04:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •