c - comparison of signed and unsigned numbers -


this question has answer here:

here question shown below , answers comes true.i know there promotion happen when compare signed , unsigned.can please tell me how signed value gets promoted?

      main()       {           signed int  = -5;           unsigned int b = 2147483648;            if(a > b)              printf("true\n");          else           printf("false\n");          } 

advanced maddy

try printing out converted value , see goes on:

int main(int argc, char **argv)   {   signed int  = -5;   unsigned int ua = a;   unsigned int b = 2147483648;    printf("a=%d  ua=%u  b=%u\n", a, ua, b);    if(a > b)     printf("true\n");   else     printf("false\n");     } 

prints

a=-5  ua=4294967291  b=2147483648 true 

share , enjoy.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -