Q:

Basic loop ends unexpectedly

I was playing with the basic sintax of C and I came up with the following piece of code:
#include <stdio.h>

int main() {
    int a = 1000;
    int b = 0;
    while (a > b) {
        a++;
        b++;
    }
    puts("Loop ended");
}

Incredibly this programme outputs Loop ended even if a will always be bigger than b no matter how much I increment them: I mean 1001 > 1 is as True as 2481298241 > 2481297241.
Please explain me what is the cause of such a weird behaviour.

A:

What you are facing is Integer overflow.

In computer programming, an integer overflow occurs when an arithmetic
  operation attempts to create a numeric value that is too large to be
  represented within the available storage space.

It was just a matter of chance though cause its UB when overflow happens.

Since an arithmetic operation may produce a result larger than the
  maximum representable value, a potential error condition may result.
  In the C programming language, signed integer overflow causes
  undefined behavior, while unsigned integer overflow causes the number
  to be reduced modulo a power of two, meaning that unsigned integers
  "wrap around" on overflow. This "wrap around" is the cause of the
  famous "Split Screen" in Pac-Man.[2] A "wrap around" corresponds to
  the fact, that e.g. if the addition of two positive integers produces
  an overflow, it may result in an unexpected result. For example with
  unsigned 32 bit integers, 4000000000u + 1000000000u = 705032704u.

A:

TL;DR answer: in your case, There is no check on the value of a. So, the increment operation will make int a value to overflow at a certain point of time. The result of overflow of a signed data type [as used in your code] is undefined. In this case, it is making a>b to evaluate to false.
Note: However, in case of unsigned data type,

computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.

A:

This is a representation error, eventually a will overflow the int container and will be less than B.Think of it like an car odometer, it will eventually say 0 but that doesn't mean that you have a brand new engine :)

