#include <iostream>
using namespace std;
int main() {
unsigned char char_values[2] = {0, 255};
char_values[1] += 1;
cout << (int)char_values[0] << endl;
cout << (int)char_values[1] << endl;
return 0;
}
On this code, I expected:
1
0
Because 255 in decimal is 1111 1111 in binary and 255 + 1 in decimal is 1 0000 0000 in binary. so I thought that char[0]
will be affected by char[1]
because of overflow but result is:
0
0
Does overflow affects other variables?