Strange output from println()

Hi to all. After some conditions were not executing on my code, I started scratching my head.

I am testing with an UNO. What is the expected output of this code?

void setup() {
  // put your setup code here, to run once:
  Serial.begin(57600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int value = 5;

  Serial.println(value);
  Serial.println(value*10000);
  Serial.println(value*20000);
  Serial.println(value*30000);
  Serial.println(value*40000);
  Serial.println(value*50000);
  Serial.println(value*100000);
  Serial.println(value*1000000);
  Serial.println(value*10000000);
  Serial.println(value*100000000);
  while(1);
}

I don't see anything wrong, but this is the output I am getting:

5
-15536
-31072
18928
200000
250000
500000
5000000
50000000
500000000

I'm wondering what is happening with the first values... When assigning value as long all is well, but is this really needed? :o

The compiler looks at the arguments and makes the data type of the output the same as the largest arguement. In the first 4 the multiplyer will fit in an int so the output is an int even though the product will not fit in an int (so overflows). 5th and on the compiler sees that multiplyer is a long so the output is a long. Best to make the value variable a long data type (or unsigned long if never negative). Or make all of the multiplyers long (* 5L, * 10000UL, etc.).l

Oh that clears it up quite well, taking note, thank you groundFungus!