I have the following code for INT_MIN/-1
. I would expect for this to have came out to be INT_MAX+1 (or 0 with rollover). However, the actual result I get is INT_MIN. This is my test code:
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
using namespace std;
int main()
{
int min=INT_MIN;
int res=min/-1;
printf("result: %i\n", res);
printf("max: %i min: %i\n", INT_MAX, INT_MIN);
return 0;
}
Is this implementation specific and/or undefined behavior?