the casting from a signed variable x to unsigned int.
the cast doesn't change the bit representation of x, just how the interpreted as a number.


int x = -1;
unsigned int ux = (int) x;

printf("%d %u\n",x,x);    //it will output -1,4294967295

when signed value compared to unsigned value, , C will implicitly cast the signed value to unsigned.

With double and float floating point

  • from int to float, it can be rounded
  • from float or int to double, it's ok
  • from double to float, it can be overflow or rounded
  • from float or double to int, the value will be truncated toward zero(去掉小數點以下的數字) or overflow.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License