What is Integer promotion?

The C rule that converts values of integer types smaller than int (char, short, bit-fields and so on) to int (or to unsigned int if int cannot represent them) before an operation. As a result, even the sum of two 8-bit uint8_t values is computed at the width of int, and the result of applying ~ has 1s in the upper bits as well. The value returns to the narrower width when the result is assigned to a variable of a smaller type. Together with the "usual arithmetic conversions", which unify types in operations mixing signed and unsigned operands, it affects the results of comparisons and bitwise operations.

Japanese name: 整数拡張

Integer promotion appears in 2 practice questions across 1 topic, including C Programming Basics.

Field: C Programming Basics

Integer promotion in the explanations

Questions that mention Integer promotion (2)

  1. unsigned char is 8 bits and int is 32 bits. Which of the following is the output when the code above is executed?
  2. uint8_t is an 8-bit unsigned integer type and int is 32 bits. Which of the following is the result when the code above is executed?

Books on C Programming Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Modulo operation Microcontroller (MCU) Alignment and padding Bit-field Buffer overflow Dangling pointer Dynamic memory allocation Function pointer Macro (#define) Memory leak

Back to the glossary