How many bytes does the C language char occupy?

problem description

A few questions arise in the book C Primer Plus. The original text is roughly as follows:
Bytes are commonly used in computers. For all machines, 1 byte is 8 bits, which is the standard definition of bytes, at least in terms of measuring storage units (but Generally speaking, the C language ensures that the char type is large enough to store the basic character set of the system (the system that implements the C language).

my question is that char must be 8 bits in C? What is the relationship between char and byte?

the expected result is to give the conclusion and the reference content, as well as the thinking process, which is more valuable than the conclusion.

C cPP
May.09,2022

conclusion: Char generally occupies 8 bits in C, the C standard does not define how many bits char is, but defines that the length of char is one byte.

The bits length of

char can be obtained from the CHAR_BIT in limit.h, and the CHAR_BIT is configurable. (that is, to buy a special case of CHAR_BIT based on the machine instead of 8)

byte is generally the same as char

byte
addressable unit of data storage large enough to hold any member of the basic character set of the execution environment
character
single-byte character
< C > bit representation that fits in a byte

personally, I think char length is related to character set encoding.

[reference 2]: https://en.wikipedia.org/wiki...
[ Reference 2]: http://www.open-std.org/jtc1/...
[ reference 2]: https://stackoverflow.com/que...


  1. Standard stipulates that char must have at least 8 digits
  2. and it is usually 8 bits. POSIX also requires that char must be 8 bits
  3. of course you can implement a c compiler that implements char to 16 bits or more, but other integer types also need to be adjusted, and this is no longer compatible with the POSIX standard
  4. so no one usually does this
  5. so generally there is no problem with using char as 8 bits. In special cases, to be on the safe side, check CHAR_BIT .
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b42882-2c611.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b42882-2c611.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?