casting - signed and unsigned in C -


code is:

#include<stdio.h> int main() {     signed x,a;     unsigned y,b;      a=(signed)10u;     b=(unsigned)-10;      y = (signed)10u + (unsigned)-10;     x = y;      printf("a=%d, b=%u",a,b);      if(x==y)         printf("\nx=%d, y=%d",x,y);     else if(x!=y)         printf("\nx=%u, y=%u",x,y);      return 0; } 

output is:

a=10, b=65526 x=0, y=0 

please explain output. working on turbo c.

y = 10 + 65526 = 65536 = 0 (mod 16-bits).

you have remember @ end of day, signed or unsigned, bits being assigned memory location. how interpreted can matter or context. writing -10 unsigned variable same writing 65526 it.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -