How to avoid integer overflow?
Posted
by noryb009
on Stack Overflow
See other posts from Stack Overflow
or by noryb009
Published on 2010-06-14T23:43:14Z
Indexed on
2010/06/14
23:52 UTC
Read the original article
Hit count: 364
In the following C++ code, 32767 + 1 = -32768.
#include <iostream>
int main(){
short var = 32767;
var++;
std::cout << var;
std::cin.get();
}
Is there any way to just leave "var" as 32767, without errors?
© Stack Overflow or respective owner