Printf Format Specifiers & C Format Specifiers Reference (GCC -Wformat)
If you match the format specifiers in a printf call to the types of your arguments, you avoid compiler warnings and undefined stack reads in variadic functions. A full list of printf format specifiers and c format specifiers includes %d or %i (for signed int), %u (for unsigned int), %ld or %lld (for long integers), %zu (for size_t), %f or %e (for floating-point doubles), %p (for addresses of void), width or precision modifiers such as %-10.2f. It can be helpful to read c format specifiers along with scanf rules so that you never get confused when reading versus printing floating-point variables, such as %f vs %lf.
Printf Format Specifiers in C: Complete C Format Specifiers Table — Technical Overview
If you match the format specifiers in a printf call to the types of your arguments, you avoid compiler warnings and undefined stack reads in variadic functions. A full list of printf format specifiers and c format specifiers includes %d or %i (for signed int), %u (for unsigned int), %ld or %lld (for long integers), %zu (for size_t), %f or %e (for floating-point doubles), %p (for addresses of void), width or precision modifiers such as %-10.2f. It can be helpful to read c format specifiers along with scanf rules so that you never get confused when reading versus printing floating-point variables, such as %f vs %lf.
#include <stdio.h>
#include <stddef.h>
int main(void) {
int count = -42;
size_t len = 128;
double pi = 3.14159265;
printf("int: %d | size_t: %zu | double: %.2f | ptr: %p\n",
count, len, pi, (void *)&count);
return 0;
}
Runnable C example
#include <stdio.h>
#include <stddef.h>
int main(void) {
int count = -42;
size_t len = 128;
double pi = 3.14159265;
printf("int: %d | size_t: %zu | double: %.2f | ptr: %p\n",
count, len, pi, (void *)&count);
return 0;
}Expected Output
int: -42 | size_t: 128 | double: 3.14 | ptr: 0x7ffc...