• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Operators

 
Albertina Gonzalez
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question about this ...
int x =10++11;
I say, that this is a invalid statement, because the operator is applicated over the variable...
What do you know?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile it and see - you'll find that this does not compile as the ++ operator has no variable to operate upon.
Corey
 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it's written as :
1) int x = 10+ +11;
It works ,the o/p is 21.
2)int x = 10 + +11;
It works ,the o/p is 21.

Is the positioning of space so important,pl.help clarify.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by geetha nagarajan:
if it's written as :
1) int x = 10+ +11;
It works ,the o/p is 21.
2)int x = 10 + +11;
It works ,the o/p is 21.

Is the positioning of space so important,pl.help clarify.

In this case, the space makes little difference as to where it is. The only thing that matters is that there is a space between the '+' signs. If they're together, they represent the increment operator in Java. If they're separate, they represent the addition operator.
Corey
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be helpful JLS 3.2

The longest possible translation is used at each step, even if the result does not ultimately make a correct program while another lexical translation would. Thus the input characters a--b are tokenized (�3.5) as a, --, b, which is not part of any grammatically correct program, even though the tokenization a, -, -, b could be part of a grammatically correct program.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic