Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Printf
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|C function to format and output text}} {{More citations needed|date=February 2015}} {{Use dmy dates|date=January 2021}} {{Use American English|date=February 2025}} {{lowercase title|title=printf}} [[Image:Printf.svg|350px|thumb|alt=Diagram illustrating syntax of printf function. The first argument to the function is a template string, which may contain format specifiers, which are introduced with the percent sign (%) character. Format specifiers instruct printf how to interpret and output values given in the corresponding arguments which follow the format string. printf replaces the format specifiers with the accordingly-interpreted contents of the remaining arguments, and outputs the result.|An example call to the printf function]] '''printf''' is a [[C standard library]] [[Function (computer programming)|function]] that [[Content format|formats]] [[Plain text|text]] and writes it to [[standard output]]. The function accepts a format [[Null-terminated string|c-string]] [[Parameter (computer programming)|argument]] and a [[variadic|variable]] number of value arguments that the function [[serialization|serializes]] per the format string. Mismatch between the format specifiers and count and [[data type|type]] of values results in [[undefined behavior]] and possibly program [[Crash (computing)|crash]] or other [[Vulnerability (computing)|vulnerability]]. The format string is [[Semantics encoding|encoded]] as a [[template language]] consisting of verbatim text and ''format specifiers'' that each specify how to serialize a value. As the format string is processed left-to-right, a subsequent value is used for each format specifier found. A format specifier starts with a [[percent sign|{{code|%}}]] character and has one or more following characters that specify how to serialize a value. The standard library provides other, similar functions that form a family of ''printf-like'' functions. The functions share the same formatting capabilities but provide different behavior such as output to a different destination or safety measures that limit exposure to vulnerabilities. Functions of the printf-family have been implemented in other programming contexts (i.e. [[programming languages|languages]]) with the same or similar [[Syntax (programming languages)|syntax]] and [[Semantics (computer science)|semantics]]. The [[scanf]] C standard library function complements printf by providing formatted input (a.k.a. [[Lexical analysis|lexing]], a.k.a. [[parsing]]) via a similar format string syntax. The name, ''printf'', is short for ''print formatted'' where ''print'' refers to output to a [[computer printer|printer]] although the function is not limited to printer output. Today, print refers to output to any text-based environment such as a [[computer terminal|terminal]] or a [[computer file|file]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)