Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java Programming Question

Name: Anonymous 2011-06-21 6:24

What does the following java code output?

int value = 0;
int count = 1;
value = count++;
System.out.println("value: "+ value + " + count: " + count );

I think it's;
value: 2 count: 1

Is this right? If it's not can someone please explain the answer to me.  Thank you.

Name: Anonymous 2011-06-21 6:43

>>4


int foo;
int bar;

bar = 1;
foo = bar++;   // foo becomes 1, bar becomes 2

bar = 1;
foo = ++bar;   // foo becomes 2, bar becomes 2


Prefix ++ increments and returns the _new_ value.
Postfix ++ increments and returns the _old_ value.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List