printf(3) Library Functions Manual printf(3) printf fprintf dprintf vprintf vfprintf vdprintf - (libc -lc) #include int printf(const char *restrict format, ...); int fprintf(FILE *restrict stream, const char *restrict format, ...); int dprintf(int fd, const char *restrict format, ...); int vprintf(const char *restrict format, va_list ap); int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap); int vdprintf(int fd, const char *restrict format, va_list ap); glibc ( feature_test_macros(7)): dprintf() vdprintf(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _GNU_SOURCE printf() format . printf() vprintf() stdout fprintf() vfprintf() stream . dprintf() fprintf() fd stdio(3). vprintf() vfprintf() vdprintf() printf() fprintf() dprintf() va_list . va_end. va_arg ap . stdarg(3). format ( stdarg(3)) . . : ( %) . % conversion specifier. ( ) flags field width precision length modifier . : %[argument$][flags][width][.precision][length modifier]conversion ( ) . '*' ( ) ( ). "%m$" '%' "*m$" '*' m 1. printf("%*d", width, num); printf("%2$*1$d", width, num); . . C99 '$' UNIX (Single UNIX Specification). '$' "%%" . '$' 1 3 2 . (" ") . LC_NUMERIC . ( setlocale(3).) POSIX '.' . printf("%'.2f", 1234567.89); "1234567.89" POSIX "1234567,89" nl_NL "1.234.567,89" da_DK. % : # " ". o ( 0 ). x X "0x" ( "0X" X). a A e E f F g G ( ). g G . m errno strerrorname_np(errno) errno . . 0 . d i o u x X a A e E f F g G . 0 - 0. (d i o u x X) 0. . - . ( ). . - 0 . ' ' () ( ) . + (+ -) . . + . C99. POSIX . ' (i d u f F g G) . : ("mjw_IN") 3 2 . locale(7) grouping thousands_sep mon_grouping/mon_thousands_sep strfmon(3). "C" . glibc 2.2 . I (i d u) . glibc 2.2.3 ("fa_IR"). ( ) . ( ). "*" "*m$" ( m) m int. '-' . . ('.') . "*" "*m$" ( m) m int. '.' . . d i o u x X a A e E f F g G s S. " " d i o u x X. hh signed char unsigned char n signed char. h short unsigned short n short. l (ell) long unsigned long n long c wint_t s wchar_t. a A e E f F g G (C99 SUSv2). ll (ell-ell). long long unsigned long long n long long. q ll. BSD . L a A e E f F g G long double. ( C99 %LF SUSv2 ). j intmax_t uintmax_t n intmax_t. wN N (C23). z size_t ssize_t n size_t. Z z z. . t ptrdiff_t n ptrdiff_t. SUSv3 . SUSv2 h ( hd hi ho hx hX hn) l ( ld li lo lx lX ln lc ls) L ( Le LE Lf Lg LG). GNU ll L llg ( Lg ) Ld ( lld ). . . : d i int . . 1. 0 0 . o u x X unsigned int (o) (u) (x X). abcdef x ABCDEF X. . 1. 0 0 . e E double [-]d.ddde+-dd ( ) 6 . E E ( e) . 00. f F double [-]ddd.ddd . 6 . . ( SUSv2 F NaN. SUSv3 F. C99 "[-]inf" "[-]infinity" "nan" NaN f "[-]INF" "[-]INFINITY" "NAN" F). g G double f e ( F E G). . 6 1. e -4 . . a A (C99 SUSv2 SUSv3) a double ( abcdef) [-]0xh.hhhhp+-d A 0X ABCDEF P. . 2 double. . d 2 0. c l int unsigned char . l wint_t ( ) wcrtomb(3) . s l: const char * ( ). ( ) ('\0') . . l: const wchar_t * . ( wcrtomb(3) ) . ( ) . . . . C ( C99 C11 SUSv2 SUSv3 SUSv4.) lc. . S ( C99 C11 SUSv2 SUSv3 SUSv4.) ls. . p void * ( %#x %#lx). n . int * (). . ( bionic C.) . m ( glibc uClibc musl API 29.) strerror(errno) ( strerrorname_np(errno) ). . % '%'. . '%%'. ( ). errno . write(2) putwc(3). : EOVERFLOW INT_MAX. dprintf() : EBADF fd . attributes(7). +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ | | | | +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ |printf(), fprintf(), | | (locale) (MT-Safe) | |vprintf(), vfprintf() | | | +----------------------+------------------------------------+---------------------------------------------------------------------------------------------+ fprintf() printf() vprintf() vfprintf() C11, POSIX.1-2008. dprintf() vdprintf() POSIX.1-2008. fprintf() printf() vprintf() vfprintf() C89, POSIX.1-2001. dprintf() vdprintf() POSIX.1-2008. 4 X/Open (SUSv1 1994) '. glibc 2.1 hh j t z a A. glibc 2.2 F C99 I. glibc 2.35 (#) m %#m. printf(foo); foo %. foo %n printf() . Pi : #include #include fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0)); " 3 10:02" weekday month : #include fprintf(stdout, "%s, %s %d, %.2d:%.2d\n", weekday, month, day, hour, min); --. : #include fprintf(stdout, format, weekday, month, day, hour, min); format . : "%1$s, %3$d. %2$s, %4$d:%5$.2d\n" "Sonntag, 3. Juli, 10:02". printf(1) asprintf(3) puts(3) scanf(3) setlocale(3) snprintf(3) strfromd(3) wcrtomb(3) wprintf(3) locale(5) 3 . . : . 6.18 16 2026 printf(3)