I suggest you try this:
Code:
#include <stdio.h>
#include <stdlib.h>
#define h1 12
#define h2 12.5f
int main()
{
int x = 0;
unsigned int y = 7;
x += ( 5 - y) * h1;
printf( "%u\n", ( 5 - y) * h1);
printf( "x = %d\n",x);
x = 0; /* Reset */
x += ( 5 - y) * h2;
printf( "%f\n", ( 5 - y) * h2);
printf( "x = %d\n",x);
return 0;
}
What I have modified is to show you the value that will be added to x in each case. Check the value of INT_MAX. You probably will find that INT_MAX is smaller than the values to be added to x. Consequently:
Originally Posted by
C99 on conversion of an integer to signed integer
Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.
Originally Posted by
C99 on conversion of a floating point number to integer
If the value of the integral part cannot be represented by the integer type, the behavior is undefined.