• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about "- -"

 
Kelvin Mak
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output is: 1
0
why there is no affect value b at line 1?
 
Keen Chen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in line 1, - -b equals "negative and negative b",so ,it's b
 
Arpana Rai
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kelvin,
this needs a little undetstanding of operators.
In the code at line 1 (- -b) will execute as
(-(-b)), so there is no change in the orginal value of b.but at verry next line (--b) 1st decrement the value of b and then will print it.
regds
Arpana
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with the space, "- -b" means you are negating b twice.
 
Arpana Rai
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,Ron..you got the point.
regds
Arpana
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just my .2$
From JLS 3.2 Lexical Translations

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