【问题标题】:For loop does not end [duplicate]For循环没有结束[重复]
【发布时间】:2019-07-21 08:01:59
【问题描述】:

为什么我不能在这个程序中停止循环?

int main()
{
 unsigned char i;
 for(i=0;i<256;i++)
  {
   printf("%d\n",i);
  }
}

【问题讨论】:

    标签: c


    【解决方案1】:

    为什么我不能在这个程序中停止循环?因为变量 i 被声明为 unsigned char 类型,范围从 0255,所以在这里 p>

    for(i=0;i<256;i++) { } /* 0,1,2..255, 0, 1 */
    

    i 永远无法到达256,这会导致无限循环。

    来自limits.h

    UCHAR_MAX   255 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多