首页 > 解决方案 > 我对“计算”无符号字符的未知行为

问题描述

问题在代码中。

#include <iostream>

int main()
{
   typedef unsigned char uchar;
   uchar u = ~uchar();

   // The following line, at least using gcc, prints: -1 �
   // The rvalue it's printed as a number, and the lvalue as a character.
   // What's the explanation of this behaviour for this particular type?
   std::cout << ~uchar() << ' ' << u << std::endl;

   return 0;
}

标签: c++stream

解决方案


推荐阅读