我发现使用模运算符的一个非常奇怪的行为.
给出以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main()
{
uint8_t x = 2;
uint8_t i;
for(i=0; i<5; i++)
{
x = (x - 1) % 10;
printf("%d ", x);
}
printf("\n");
}
Run Code Online (Sandbox Code Playgroud)
我希望结果1 0 3 4 2,但我得到了1 0 255 4 3.
我认为它与整体推广有关,但我不明白转换是如何完成的.