long, unsigned long, int

What happens if I would write a program like this:

int i=0;
void setup(){

}

void loop(){

i=i+1;

}

When the i hits 32,767 would it go back to 0 or would it go to -32,768 or just stay 32,767, and
what happens with long or unsigned long?
Thank you

It took you longer to type that post than it would to try it out.

(The compiler would most likely optimise the whole lot away, because you never use i)

AWOL:
The compiler would most likely optimise the whole lot away, because you never use i

True, but not if it’s used in a serial print

OldSteve:
True, but not if it's used in a serial print

For that, you'd need a Serial.begin.

AWOL:
For that, you'd need a Serial.begin.

I just mentioned that as a further hint to Nejcar. :slight_smile:

Nejcar:
What happens if I would write a program like this:
...
When the i hits 32,767 would it go back to 0 or would it go to -32,768 or just stay 32,767, and
what happens with long or unsigned long?
Thank you

Answer is well explained if you look at learning > reference at the top of this page. Here is the link to minimize your work, but you have to click and read yourself, as I can't do that for you.

Nejcar:
When the i hits 32,767 would it go back to 0 or would it go to -32,768 or just stay 32,767, and
what happens with long or unsigned long?

The contents of the variable would go from 0x7FFF to 0x8000. For a signed integer that's -32768. For an unsigned integer, long integer, or unsigned long integer that would be 32768.