C Data Types and Format Specifiers
int, char, float, double and fixed-width types — and how printf prints them.
Beginner
| Type | Typical size | printf |
|---|---|---|
char | 1 byte | %c |
int | 4 bytes (2 on AVR!) | %d |
long | 4–8 bytes | %ld |
float | 4 bytes | %f |
double | 8 bytes | %f (%lf in scanf) |
Sizes depend on the platform, so embedded code uses <stdint.h>: uint8_t, int16_t, uint32_t — exact widths everywhere.
uint16_t adc = 1023;
printf("ADC = %u, V = %.2f\n", adc, adc * 5.0 / 1023);
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.