Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

= operator

 
Anju sethi
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very basic Question.

//code in a main
int x;
int y[] = {1, 2};
int c =0;
x = y[0] = c;//one
System.out.println(x + "" + y[0] + y[1]); //o/p is 1 0 2

I am a bit confused in whether the statement //one will be evaluated left to right or right to left. As per rule = operator has right associatity, thus output should be 0 0 2 unlike what is comming.

can anyone explain why is it so?
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Anju,

After copy, paste and run your code in my netBeans IDE the output is 002.

It's supposed to be correct, isn't it ?

Are you sure you're running the final compiled version of the class ?
 
Anju sethi
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes..just nw checked. i was running old class file.
thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic