• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unary Operator ()

 
Paul Callaly
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Bit of a Programming 101 question but what does the unary operator () do?
The following list might also be helpful for people studying for the test
Thanx, Paul
Unary operators are: ++ -- + - ! ~ ()
Arithmetic operators are: * / % + -
Shift operators are: << >> >>>
Comparison operators are: < <= > >= instanceof == !=
Bitwise operators are: & ^ |
Short-circuit operators are: && ||
Conditional operators are: ?:
Assignment operators are: = "op="
 
Yuriy Grechukhin
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if () is considered an operator, but if it is, I would say it returns unchanged value of what's inside it.
Consider this:
7++ evaluates to 8
5+6 evaluates to 11
Cat instanceof Animal evaluates to true
b = 5 evaluates to 5 (can be checked by a = b = 5, a will be 5 as well)
so since all those expressions evaluate to something (an we consider parantheses an operator) whatever is inside the () will evaluate to itself:
(5) returns 5
[ March 04, 2004: Message edited by: Yuriy Grechukhin ]
 
S Anand
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul
I don't think () is considered as an operator.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by S Anand:
Hi Paul
I don't think () is considered as an operator.

I think it is a casting operator. Example follows...

Also for object casting too...
Hope this helps.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
you have postfix() like in a method/constructor: aMethod() Aconstructor()
and you can have cast: (type)e
post fix is higher in precedence than the unary operators, and cast is lower than unary.
is this what you meant?
Davy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic