#include <limits.h>
#include <iostream>
int main()
{
for(unsigned char ch = 0; ch <= UCHAR_MAX; ++ch){
std::cout << (int)ch << std::endl;
}
}
Can you see the bug?
ch comes UCHAR_MAX,
++ch becomes 0 by overflow.