does the incrementation of unsigned int cause undefined behavior when the variable reach the Max

Viewed 7194

I have a counter in my code and I want my counter back to 0 when it reach the unsigned int max value. I tested with a small code and it works but I do not know if it's an undefined behaviour

#include <stdio.h>
#include <string.h>

main()
{
  unsigned int a = 0;
  a= ~a; // Max value of unsigned int 
  printf("%u \n", a );
  a= a+1; //is it allowed to increment "a" when "a" reach the Max ? 
  printf("%u \n", a ); // display 0

}
2 Answers
Related