C Programming Basics

Which of the following is what the C standard specifies about the size of the int type?

  1. AIt is fixed at 32 bits in every implementation
  2. BOnly that it is at least 16 bits is specified; the actual size is decided by the implementation
  3. CIt is specified to equal the width of the CPU's addresses, so it is 64 bits on a 64-bit CPU
Show answer and explanation

Answer: B. Only that it is at least 16 bits is specified; the actual size is decided by the implementation

The C standard only requires that int can represent at least −32767 to 32767 (that is, 16 bits or more); the actual size is decided by the implementation (the combination of compiler and target CPU). With compilers for 16-bit microcontrollers int may be 16 bits, while on most PCs and 32-bit microcontrollers it is 32 bits. Even on 64-bit Linux and Windows, int generally stays 32 bits and pointers become 64 bits. When an integer of a fixed size is needed, int32_t and similar types from stdint.h are used.

  • A. 32 bits is the size in many environments, but it is not a rule of the standard. Some implementations use a 16-bit int.
  • B. Correct. The standard only sets a lower limit on the range, and the implementation decides the actual size.
  • C. Even on 64-bit Linux and Windows, int is generally 32 bits.
Practice this topic Back to topic

Books on C Programming Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More C Programming Basics questions

  1. In embedded programs, variables that hold the value of a 32-bit peripheral register are often declared with uint32_t from stdint.h rather than unsigned int. Which of the following is the main reason?
  2. Which of the following is the output when the code above, which includes a division of integers, is executed?
  3. Which of the following is the output when the code above, which uses prefix and postfix ++, is executed?
  4. Which of the following is the output when the code above, with = written in the condition of an if statement, is executed?
  5. The code above was written to check whether bit 2 of the register value reg is 1. Which of the following is the result when it is executed?