sign and unsigned numbers, guess what the output is.


char c = -1;
unsigned short  w = c;  //c treated as FFFF
printf("%x", w);
w = 1;
if(w < c)  //c is not treated as FFFF, but -1. things can be different on other systems
  printf("weird");

On Visual Studio 2010 without extension, x prints FFFF, and it’s not ‘weird’.
Therefore, c gets converted to unsigned number only in the assignment, not in (w < c).
However, ‘weird’ can be printed on some system. So it depends on implementation.

Advertisements
Previous Post
Comments are closed.
%d bloggers like this: