Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What's the difference between a long int and an unsigned int?


Asked by Julie Ali on Dec 05, 2021 FAQ



The argument is interpreted as a short int or unsigned short int (only applies to integer specifiers: i, d, o, u, x and X). The argument is interpreted as a long int or unsigned long int for integer specifiers (i, d, o, u, x and X), and as a wide character or wide character string for specifiers c and s.
Likewise,
The basic difference between the type int and long is of their width where int is 32 bit, and long is 64 bits. The types int and long when counted in bytes instead of bits the type int is 4 bytes and the type long is just twice if type int i.e. 8 bytes.
Indeed, In computing. The number 2,147,483,647 (or hexadecimal 7FFF,FFFF 16) is the maximum positive value for a 32-bit signed binary integer in computing. It is therefore the maximum value for variables declared as integers (e.g., as int) in many programming languages, and the maximum possible score, money, etc. for many video games.
Consequently,
From the C specification, section 6.7.2: Meaning that unsigned, when not specified the type, shall default to unsigned int. So writing unsigned a is the same as unsigned int a. Thanks for contributing an answer to Stack Overflow!
Next,
Even doing this, you will need the cast from unsigned int to unsigned char, because the compiler will ultimately still think that you didn't mean to down-convert the way that you did. The warning is telling you that what you are doing isn't defined in all cases.