示例:
/*** @brief how about integer-underflow-overflow? show you here.* @author wen`xuanpei* @email 15873152445@163.com(query for any question here)*/
#define _CRT_SECURE_NO_WARNINGS//support c-library in Microsoft-Visual-Studio
#include <stdio.h>int main(){/*signed*/char chUnderFlow = (char)(-128-1), chOverFlow = (char)(127+1);printf("%hhd, %hhd\n", chUnderFlow, chOverFlow);/*unsigned*/unsigned char uchUnderFlow = (unsigned char)(0-1), uchOverFlow = (unsigned char)(255+1);printf("%hhu, %hhu\n", uchUnderFlow, uchOverFlow);getchar();return 0;
}
1)编译运行
2)要点分析
1)整数最小值下溢出越界后,变成最大值
2)整数最大值上溢出越界后,变成最小值
3)回绕(轮回)是一种形象的说法,强调物极必反,强调否极泰来
尾声:
其它不明白的地方不用过于纠结,那只是在浪费时间。学得多了,回过头来看自然融会贯通。