fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. int main(void) {
  5. // your code goes here
  6. int32_t x = (0x80000000 - 3);
  7.  
  8. int i;
  9. for( i = 0; i < 5; ++i )
  10. {
  11. int32_t y = x + 1; // this may cause rollover from 0x7fffffff (positive) to 0x80000000 (negative)
  12.  
  13. printf("\n" "x = 0x%08X, y = 0x%08X", x, y );
  14.  
  15. if( ( y - x ) >= 1 ) // Method 1
  16. printf(" - true ");
  17. else
  18. printf(" - FALSE");
  19.  
  20. int32_t z = ( y - x ); // Method 2
  21. if( ( z ) >= 1 )
  22. printf(" - true ");
  23. else
  24. printf(" - false");
  25.  
  26. ++x;
  27. }
  28. }
  29.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
x = 0x7FFFFFFD, y = 0x7FFFFFFE - true  - true 
x = 0x7FFFFFFE, y = 0x7FFFFFFF - true  - true 
x = 0x7FFFFFFF, y = 0x80000000 - true  - true 
x = 0x80000000, y = 0x80000001 - true  - true 
x = 0x80000001, y = 0x80000002 - true  - true