关于unsigned char和signed char的问题
cssin 2002-06-16 12:18:41 现在我正在学习C++,用的书是《C++ Primer》(3rd Edition)。在这本书的Chapter 3中介绍char类型时,有这么一句话:
An 8-bit signed char may represent the values -128 through 127;
an unsigned char, 0 through 255.
所以我写了段代码对其进行测试:
#include <iostream>
using namespace std;
int main()
{
signed char c = 127;
cout << c+1 << endl;
return 0;
}
编译通过,但是输出128。
这是为什么?
PS:我用的编译器是Dev-C++带的g++。