Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ATOMIC_ |
Lock-free property of type atomic_ |
? | M | <stdatomic.h> |
C11 | ||||||
atomic_ |
Atomic character type | ? | T | <stdatomic.h> |
C11 | ||||||
atomic_ |
Atomic character type | ? | T | <stdatomic.h> |
C11 | ||||||
atomic_ |
Atomic character type | ? | T | <stdatomic.h> |
C11 | ||||||
CHAR_ |
Number of bits in unsigned char |
L | M | <limits.h> |
C89 | C90 | C95 | C99 | C11 | ||
CHAR_ |
Maximum value of char |
L | M | <limits.h> |
C89 | C90 | C95 | C99 | C11 | ||
CHAR_ |
Minimum value of char |
L | M | <limits.h> |
C89 | C90 | C95 | C99 | C11 | ||
char |
Character type | L | T | Native | C89 | C90 | C95 | C99 | C11 | ||
SCHAR_ |
Maximum value of signed char |
L | M | <limits.h> |
C89 | C90 | C95 | C99 | C11 | ||
SCHAR_ |
Minimum value of signed char |
L | M | <limits.h> |
C89 | C90 | C95 | C99 | C11 | ||
signed char |
Character type | L | T | Native | C89 | C90 | C95 | C99 | C11 | ||
UCHAR_ |
Maximum value of unsigned char |
L | M | <limits.h> |
C89 | C90 | C95 | C99 | C11 | ||
unsigned char |
Character type | L | T | Native | C89 | C90 | C95 | C99 | C11 |
In C, types are built on the concept of a byte, a sequence of 8 or more bits treated as a unit. It is the smallest unit of data that a C program can manipulate, and the smallest addressable unit of memory. The memory that holds the program's data is considered to be made of distinctly addressable bytes. All types have an underlying representation as a sequence of bytes.
The type that represents a
byte is unsigned char
, which has a range from zero to
UCHAR_
,
which is at least [0, +255]. Each bit has the value
+2n, where n runs from zero
to one less than CHAR_
(which therefore must be at least 8). There is no sign bit,
and there are no padding bits. Use %u,
%o, %x or %X with
printf
to print an unsigned char
as a number. Use
%hhu, %hho or %hhx
with scanf
to scan an unsigned char
.
The type signed char
has the same number of bits as
unsigned char
, and runs from SCHAR_
to SCHAR_
,
which is at least [−127, +127]. There are no padding bits.
Use %d or %i with printf
to print a signed char
as a number. Use
%hhd or %hhi with scanf
to scan a signed char
.
The type char
has exactly the same
representation as either unsigned char
or signed char
, and it is the type that a
character should be
stored in. It can be either a signed or unsigned type, with
the range CHAR_
to
CHAR_
.
CHAR_
will be negative if it is signed. Arrays of char
are used to represent sequences
of single-byte and multibyte characters, and are
often passed around by reference using char *
.
Use "%c" to print a single char
with printf
, or to scan a single
character with scanf
. The field width allows a
specific number of characters to be scanned.
The types char
, unsigned char
and signed char
are the character
types. The sizeof
operator yields 1 for all
character types. char *
, unsigned char *
and signed char *
can be punned safely
with void *
,
when used with va_
, for example.
atomic_
is an alias for _Atomic unsigned char
. atomic_
is an alias for _Atomic signed char
. atomic_
is an alias for _Atomic char
. These types are lock-free always if
ATOMIC_
is 2
, sometimes if 1
, and never if 0
.