Jump to: navigation, search



The printf() function writes data formated as specified in the string fmt, to the standard output stream.


All characters in fmt are printed as is, except for formating directives starting with %. Each of these directives correspond to one argument in the variable argument list. In addition to the %, a directive contain optional flags and a conversion type.

These are the conversion types:

code conversion data type
d signed decimal int
i signed decimal int
u unsigned decimal int
o octal int
x hexadecimal lower case int
X hexadecimal upper case int
f decimal notation double
F decimal notation double
e e notation double
E e notation double
g decimal or e notation double
G decimal or e notation double
c character char
s string char *
P address void *

Usage example:


int main()
    int n=5;

    printf("n=%d\n", n);
    return 0;

Full program, strictly conforming; public domain; past reviewers: {{{past-reviewers--no-line-breaks}}}; current reviews: {{{later-reviews--"none"-or-empty}}}

Return value

If successful, the printf() function returns the number of written characters. To indicate an error, -1 is returned.


Declared in stdio.h

The C89/C99 prototype is:

int printf(const char *fmt, ...);
Personal tools
Personal tools
not logged in