long int problem

int a=32767;
long int b;
b=a+1;
serial.println(b);

even though i have declared b as long.i ma getting negative answer as -32767.i mean overflowing.whats the reason.

Because an int plus an int is still only an int - the calculation is done before the assignment - in this case it's actually done at compilation time by the optimizer.

Force it to be long and you'll get the right result:

int a=32767;
long int b;
b=(long)a+1L;
serial.println(b);