C language: implicit type conversion example


One of the most hardcore stuff in C language is implicit type conversion. If you don’t watch for it – you will be in big trouble. Take a look at this code:

#include <stdio.h>

int main (void)
{
int a = -10;
unsigned int b = 5U;
long int c = a + b; // signed + unsigned

printf ("1) (signed int)a -10 will look as unsigned like this: %u\n", a);

printf ("2) (signed)a(-10) + (unsigned)b(5) = %ld\n", c);

return 0;
}

Implicit type conversion ranks:

bool
 char
  unsigned char
   short int
    unsigned short int
     int
      unsigned int
       long int
        unsigned long int
         long long int
          unsigned long long int
           float
            double
             long double

This entry was posted in C language (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.