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!
===Length field=== The length field can be omitted or be any of: {{Table alignment}} {| class="wikitable col1center" |- ! Text ! Description |- | {{tt|hh}} | For integer types, causes {{tt|printf}} to expect an {{tt|int}}-sized integer argument which was promoted from a {{tt|char}}. |- | {{tt|h}} | For integer types, causes {{tt|printf}} to expect an {{tt|int}}-sized integer argument which was promoted from a {{tt|short}}. |- | {{tt|l}} | For integer types, causes {{tt|printf}} to expect a {{tt|long}}-sized integer argument. For floating-point types, this is ignored. {{tt|float}} arguments are always promoted to {{tt|double}} when used in a [[varargs]] call.<ref name="c99io">{{cite standard| publisher= [[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]] | year= 1999 | title-link= C99 | title= ISO/IEC 9899:1999(E): Programming Languages β C | section= 7.19.6.1 | at= para. 7 }}</ref> |- | {{tt|ll}} | For integer types, causes {{tt|printf}} to expect a {{tt|long long}}-sized integer argument. |- | {{tt|L}} | For floating-point types, causes {{tt|printf}} to expect a {{tt|long double}} argument. |- | {{tt|z}} | For integer types, causes {{tt|printf}} to expect a {{tt|size_t}}-sized integer argument. |- | {{tt|j}} | For integer types, causes {{tt|printf}} to expect a {{tt|intmax_t}}-sized integer argument. |- | {{tt|t}} | For integer types, causes {{tt|printf}} to expect a {{tt|ptrdiff_t}}-sized integer argument. |} Platform-specific length options came to exist prior to widespread use of the ISO C99 extensions, including: {{Table alignment}} {| class="wikitable col1center" |- ! Text ! Description ! ''Commonly found platforms'' |- | {{tt|I}} | For signed integer types, causes {{tt|printf}} to expect {{tt|ptrdiff_t}}-sized integer argument; for unsigned integer types, causes {{tt|printf}} to expect {{tt|size_t}}-sized integer argument. || [[Win32]]/[[Win64]] |- | {{tt|I32}} | For integer types, causes {{tt|printf}} to expect a 32-bit ([[double word]]) integer argument. || Win32/Win64 |- | {{tt|I64}} | For integer types, causes {{tt|printf}} to expect a 64-bit (quad word) integer argument. || Win32/Win64 |- | {{tt|q}} | For integer types, causes {{tt|printf}} to expect a 64-bit (quad word) integer argument. || [[BSD]] |} ISO C99 includes the <code>[[inttypes.h]]</code> header file that includes a number of [[Macro (computer science)|macros]] for platform-independent {{code|printf}} coding. For example: {{code|printf("%" PRId64, t);|c}} specifies decimal format for a [[Integer (computer science)|64-bit signed integer]]. Since the macros evaluate to a [[string literal]], and the compiler [[concatenates]] adjacent string literals, the expression {{code|"%" PRId64|c}} compiles to a single string. Macros include: {| class="wikitable" |- ! Macro ! Description |- | {{tt|PRId32}} | Typically equivalent to {{tt|I32d}} (''Win32/Win64'') or {{tt|d}} |- | {{tt|PRId64}} | Typically equivalent to {{tt|I64d}} (''Win32/Win64''), {{tt|lld}} (''32-bit platforms'') or {{tt|ld}} (''64-bit platforms'') |- | {{tt|PRIi32}} | Typically equivalent to {{tt|I32i}} (''Win32/Win64'') or {{tt|i}} |- | {{tt|PRIi64}} | Typically equivalent to {{tt|I64i}} (''Win32/Win64''), {{tt|lli}} (''32-bit platforms'') or {{tt|li}} (''64-bit platforms'') |- | {{tt|PRIu32}} | Typically equivalent to {{tt|I32u}} (''Win32/Win64'') or {{tt|u}} |- | {{tt|PRIu64}} | Typically equivalent to {{tt|I64u}} (''Win32/Win64''), {{tt|llu}} (''32-bit platforms'') or {{tt|lu}} (''64-bit platforms'') |- | {{tt|PRIx32}} | Typically equivalent to {{tt|I32x}} (''Win32/Win64'') or {{tt|x}} |- | {{tt|PRIx64}} | Typically equivalent to {{tt|I64x}} (''Win32/Win64''), {{tt|llx}} (''32-bit platforms'') or {{tt|lx}} (''64-bit platforms'') |}
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)