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:
| 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:
#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, ...);









