c - Implicit Type Conversion -


#include<stdio.h> int main(void) {    signed int a=-1;   unsigned int b=1;   int c= a+b;   printf("%d\n",c);    return 0;   } 

according rule of implicit type conversion, if 1 operand unsigned int,the other converted unsigned int , result unsigned int in binary operation. here b unsigned int, a should type casted unsigned int.as unsigned int +ve , value of a 1.so c=1+1=2.but output 0.how ?

-1, when cast unsigned become largest possible value type -- e.g. 32-bit unsigned, it'll 4,294,967,295. when add 1 that, value "wraps around" 0.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -