Contents

Description

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

Fmt

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:

codeconversiondata type
dsigned decimalint
isigned decimalint
uunsigned decimalint
ooctalint
xhexadecimal lower caseint
Xhexadecimal upper caseint
fdecimal notationdouble
Fdecimal notationdouble
ee notationdouble
Ee notationdouble
gdecimal or e notationdouble
Gdecimal or e notationdouble
ccharacterchar
sstringchar *
Paddressvoid *

Usage example:

#include<stdio.h>

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.

Prototype

Declared in stdio.h

The C89/C99 prototype is:

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