int类型bit都满了之后继续累加

uint8_t的最大值是255,如果再加1那低8位都是0,最后结果也是0

 

#include<stdio.h>
#define uint8_t unsigned char
int main(int argc,char **argv)
{
  uint8_t a=253;
  int i;
  for(i=0;i<10;i++){
    printf("a = %d \n",a++);
  }
  return 0;
}

 

 

# gcc -o add add.c
# ./add
a = 253 
a = 254 
a = 255 
a = 0       <<<bit占满后从0开始
a = 1 
a = 2 
a = 3 
a = 4 
a = 5 
a = 6 

 

posted @ 2019-08-29 09:16  liqinglucky  阅读(383)  评论(0编辑  收藏  举报