Data Types, Sizes¶
Standard Data Types And Their Sizes¶
C knows about the following base types
char
: one byte in the machine’s character set (mostly ASCII, nowadays)int
: integer, as the processor architecture sees fit (nowadays 32 bits, mostly)float
: single-precision floating pointdouble
: double-precision floating point
Attention
C does not specify the width of any of these types! (“machine dependent”)
Integer Variants (“Qualifiers”)¶
Width modification
short int
(abbreviated:short
)long int
(abbreviated:long
)long double
Signs (for all integer types)
signed
unsigned
Helpers
CHAR_BITS
: a macro, bits per character (generally 8, nowadays)sizeof
: operator, width in characters
Widths¶
Integer widths on different architectures
Type |
|
|
|
---|---|---|---|
|
8 |
8 |
8 |
|
32 |
32 |
32 |
|
16 |
16 |
16 |
|
32 |
64 |
32 |
Standard Type Aliases (from <stdint.h>
)
Signed |
Unsigned |
---|---|
|
|
|
|
|
|
|
|
When to use which …
It depends (as always)
Program flow (loop counters etc.) are natural integers (preferably
int
orunsigned int
)In memory data structure where memory is tight:
short
Protocols, persistence:
<stdint.h>