Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

i have a source code about ++i and i++

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class FromLeftToRight {

// Here H stands for famous physicist WERNER HEISENBERG(1901-1976)
// Even Heisenberg Uncertainty Principle does not apply here!

// Adding or substracting zeroH() will NOT affect your result
// Multiplying or Dividing oneH() will NOT affect your result
// These are the secrets of measuring your system without disturbing the system

public static int zeroH(String s, int n) {
System.out.println(s + ": " + n);
return 0;
}
public static int oneH(String s, int n) {
System.out.println(s + ": " + n);
return 1;
}

public static void main(String arg[]) {
System.out.println("//*****************");
System.out.println("int x = 0;");
System.out.println("x = x++; ");
int x = 0;

// adding 0's will not affect the result
// x = x++; The equivalent statment of the following
x = zeroH("Initial", x) + x++ + zeroH("Before assignment", x);

zeroH("After assignment", x);

System.out.println("//*****************");
System.out.println("int y = 5;");
System.out.println("y = y++ + y++;");
int y = 5;

// adding 0's will not affect the result
//y = y++ + y++; The equivalent statment of the following
y = zeroH("Initial", y) + y++ + zeroH("In the middle", y) + y++ + zeroH("Before assignment", y);

zeroH("After assignment", y);
System.out.println("//*****************");
System.out.println("int z = 5;");
System.out.println("z = z++ * z++;");
int z = 5;

// multiplying 1's will not affect the result
//z = z++ * z++; The equivalent statment of the following
z = oneH("Initial", z) * z++ * oneH("In the middle", z) * z++ * oneH("Before assignment", z);

zeroH("After assignment", z);
System.out.println("//*****************");
}
}

// The output
//*****************
int x = 0;
x = x++;
Initial: 0
Before assignment: 1
After assignment: 0
//*****************
int y = 5;
y = y++ + y++;
Initial: 5
In the middle: 6
Before assignment: 7
After assignment: 11
//*****************
int z = 5;
z = z++ * z++;
Initial: 5
In the middle: 6
Before assignment: 7
After assignment: 30
//*****************
 
Sam Wang
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe the code above can explain something useful.
reply
    Bookmark Topic Watch Topic
  • New Topic