Syntax
#include <stdio.h> int printf(const char *format-string, argument-list);Description
printf formats and prints a series of characters and values to the standard output stream stdout. The format-string consists of ordinary characters, escape sequences, and format specifications. The ordinary characters are copied in order of their appearance to stdout. Format specifications, beginning with a percent sign (%), determine the output format for any argument-list following the format-string.
The format-string is read left to right. When the first format specification is found, the value of the first argument after the format-string is converted and output according to the format specification. The second format specification causes the second argument after the format-string to be converted and output, and so on through the end of the format-string. If there are more arguments than there are format specifications, the extra arguments are evaluated and ignored. The results are undefined if there are not enough arguments for all the format specifications. A format specification has the following form:
>>ÄÄ%ÄÄÂÄÄÄÄÂÄÄÂÄÄÄÄÄÄÄÂÄÄÂÄÄÄÄÄÄÄÂÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÂÄÄÄÂÄÄtypeÄÄ><
ÀÄn$ÄÙ ÀÄflagsÄÙ ÀÄwidthÄÙ ÀÄ.ÄÄprecisionÄÙ ÃÄhÄ´
ÃÄlÄ´
ÀÄLÄÙ
Each field of the format specification is a single character or number signifying a particular format option. The type character, which appears after the last optional format field, determines whether the associated argument is interpreted as a character, a string, a number, or pointer. The simplest format specification contains only the percent sign and a type character (for example, %s).
The %n$ syntax should always be used when format strings are stored in translatable text such as message catalog files. This is necessary because sentence structures and order of arguments could vary in different languages. For example, in the statement: printf ( format, month, day, year )
The following optional fields control other aspects of the formatting:
Field
h
Each field of the format specification is discussed in detail below. To print a percent sign character, use %%.
In extended mode, printf also converts floating-pointvaluesofNaNandinfinitytothestrings" NAN "or" nan "and" INFINITY "or" infinity " .Thecaseandsignofthestringisdeterminedbytheformatspecifiers . SeeInfinityandNaNSupportformoreinformationoninfinityandNaNvalues .
The type characters and their meanings are given in the following
table: ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³Char
- ³Argument ³OutputFormat ³
³ acter ³ ³ ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ d, i ³ Integer ³ Signed decimal integer. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ o ³ Integer ³ Unsigned octal integer. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ u ³ Integer ³ Unsigned decimal integer. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ x ³ Integer ³ Unsigned hexadecimal integer, using ³
³ ³ ³ abcdef. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ X ³ Integer ³ Unsigned hexadecimal integer, using ³
³ ³ ³ ABCDEF. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ f ³ Double ³ Signed value having the form ³
³ ³ ³ [-]dddd.dddd, where dddd is one or ³
³ ³ ³ more decimal digits. The number of ³
³ ³ ³ digits before the decimal point ³
³ ³ ³ depends on the magnitude of the ³
³ ³ ³ number. The number of digits after ³
³ ³ ³ the decimal point is equal to the ³
³ ³ ³ requested precision. NaN and infinity ³
³ ³ ³ values are printed in lowercase ("nan" ³
³ ³ ³ and "infinity"). ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ F ³ Double ³ In extended mode,identical to the "f" ³
³ ³ ³ format except that NaN and infinity ³
³ ³ ³ values are printed in uppercase ("NAN" ³
³ ³ ³ and "INFINITY"). In modes other than ³
³ ³ ³ extended, "F" is treated like any ³
³ ³ ³ other character not included in this ³
³ ³ ³ table. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ e ³ Double ³ Signed value having the form ³
³ ³ ³ [-]d.dddd"e"[sign] ddd, where d is a ³
³ ³ ³ single-decimal digit, dddd is one or ³
³ ³ ³ more decimal digits, ddd is 2 or 3 ³
³ ³ ³ decimal digits, and sign is + or -. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ E ³ Double ³ Identical to the "e" format except ³
³ ³ ³ that "E" introduces the exponent ³
³ ³ ³ instead of "e". ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ g ³ Double ³ Signed value printed in "f" or "e" ³
³ ³ ³ format. The "e" format is used only ³
³ ³ ³ when the exponent of the value is less ³
³ ³ ³ than -4 or greater than precision. ³
³ ³ ³ Trailing zeros are truncated, and the ³
³ ³ ³ decimal point appears only if one or ³
³ ³ ³ more digits follow it. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ G ³ Double ³ Identical to the "g" format except ³
³ ³ ³ that "G" introduces the exponent ³
³ ³ ³ (where appropriate) instead of "g". ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ c ³ Character ³ Single character. The "int" argument ³
³ ³ ³ is converted to an unsigned character. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ lc, C ³ Wide character ³ Multibyte character (converted as if ³
³ ³ ³ by a call to wctomb) pointer to an ³
³ ³ ³ array of "char". ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ s ³ String ³ Characters printed up to the first ³
³ ³ ³ null character (\"0") or until preci- ³
³ ³ ³ sion is reached. If you specify a ³
³ ³ ³ null string, "(NULL)" is printed. ³
ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
ÚÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ ls, S ³ Wide-character ³ Multibyte characters, printed up to ³
³ ³ string ³ the first "wchar_t" null character ³
³ ³ ³ ("L\0") is encountered in the wide- ³
³ ³ ³ character string, or until the speci- ³
³ ³ ³ fied precision is reached. Conversion ³
³ ³ ³ takes place as if by a call to ³
³ ³ ³ wcstombs. The displayed result does ³
³ ³ ³ not include the terminating null char- ³
³ ³ ³ acter. If you do not specify the pre- ³
³ ³ ³ cision, you must end the ³
³ ³ ³ wide-character string with a null ³
³ ³ ³ character. A partial multibyte char- ³
³ ³ ³ acter cannot be written. If you ³
³ ³ ³ specify a null string, "(NULL)" is ³
³ ³ ³ printed. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ n ³ Pointer to ³ Number of characters successfully ³
³ ³ integer ³ written so far to the stream or ³
³ ³ ³ buffer; this value is stored in the ³
³ ³ ³ integer whose address is given as the ³
³ ³ ³ argument. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ p ³ Pointer ³ Pointer to void converted to a ³
³ ³ ³ sequence of printable characters. ³
ÃÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ % ³ `%' ³ Use to print a "%" symbol. ³
ÀÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
The flag characters and their meanings are as follows (notice that
more than one flag can appear in a format specification): ÚÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Flag ³ Meaning ³ Default ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ - ³ Left-justify the result within ³ Right-justify.
³
³ ³ the field width. ³ ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ + ³ Prefix the output value with a ³ Sign appears only ³
³ ³ sign (+ or -) if the output ³ for negative signed ³
³ ³ value is of a signed type. ³ values (-). ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ blank(' ')³ Prefix the output value with a ³ No blank. ³
³ ³ blank if the output value is ³ ³
³ ³ signed and positive. The "+" ³ ³
³ ³ flag overrides the blank flag ³ ³
³ ³ if both appear, and a positive ³ ³
³ ³ signed value will be output ³ ³
³ ³ with a sign. ³ ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ # ³ When used with the "o", "x", or ³ No prefix. ³
³ ³ "X" formats, the "#" flag pre- ³ ³
³ ³ fixes any nonzero output value ³ ³
³ ³ with "0", "0"x, or "0"X, ³ ³
³ ³ respectively. ³ ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ # ³ When used with the "f", "F", ³ Decimal point ³
³ ³ "e", or "E" formats, the "#" ³ appears only if ³
³ ³ flag forces the output value to ³ digits follow it. ³
³ ³ contain a decimal point in all ³ ³
³ ³ cases. ³ ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ # ³ When used with the "g" or "G" ³ Decimal point ³
³ ³ formats, the "#" flag forces ³ appears only if ³
³ ³ the output value to contain a ³ digits follow it; ³
³ ³ decimal point in all cases and ³ trailing zeros are ³
³ ³ prevents the truncation of ³ truncated. ³
³ ³ trailing zeros. ³ ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ # ³ When used with the "ls" format, ³ Precision indicates ³
³ ³ the "#" flag causes precision ³ the maximum number ³
³ ³ to be measured in "wchar_t" ³ of bytes to be ³
³ ³ characters. ³ output. ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ "0" ³ When used with the "d", "i", ³ Space padding. ³
³ ³ "o", "u", "x", "X", "e", "E", ³ ³
³ ³ "f", "F"" g", or "G" formats, ³ ³
³ ³ the "0" flag causes leading ³ ³
³ ³ "0"'s to pad the output to the ³ ³
³ ³ field width. The "0" flag is ³ ³
³ ³ ignored if precision is speci- ³ ³
³ ³ fied for an integer or if the ³ ³
³ ³ `"-"' flag is specified. ³ ³
ÃÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ ' ³ Formats with the thousands ³ No grouping char- ³
³ ³ grouping character of the ³ acter. ³
³ ³ appropriate locale for the ³ ³
³ ³ decimal conversions (%i, %d, ³ ³
³ ³ %u, %f, %g, or %G). ³ ³
ÀÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
The # flag should not be used with c, lc, d, i, u, s, or p types.
Width is a nonnegative decimal integer controlling the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added on the left or the right (depending on whether the - flag is specified) until the minimum width is reached.
Width never causes a value to be truncated; if the number of characters in the output value is greater than the specified width, or width is not given, all characters of the value are printed (subject to the precision specification).
For the ls type, width is specified in bytes. If the number of bytes in the output value is less than the specified width, single-byte blanks are added on the left or the right (depending on whether the - flag is specified) until the minimum width is reached.
The width specification can be an asterisk (* or *n$), in which case an argument from the argument list supplies the value. The width argument must precede the value being formatted in the argument list.
Precision is a nonnegative decimal integer preceded by a period, which specifies the number of characters to be printed or the number of decimal places. Unlike the width specification, the precision can cause truncation of the output value or rounding of a floating-point value.
The precision specification can be an asterisk (* or *n$), in which case an argument from the argument list supplies the value. The precision argument must precede the value being formatted in the argument list.
The interpretation of the precision value and the default when the
precision is omitted depend upon the type, as shown in the
following table: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Type ³ Meaning ³ Default ³
ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ i ³ Precision specifies the minimum ³ If precision is "0" or ³
³ d ³ number of digits to be printed. ³ omitted entirely, or ³
³ u ³ If the number of digits in the ³ if the period (.) ³
³ o ³ argument is less than precision, ³ appears without a ³
³ x ³ the output value is padded on ³ number following it, ³
³ X ³ the left with zeros. The value ³ the precision is set ³
³ ³ is not truncated when the number ³ to 1. ³
³ ³ of digits exceeds precision. ³ ³
ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ f ³ Precision specifies the number ³ Default precision is ³
³ F ³ of digits to be printed after ³ six. If precision is ³
³ e ³ the decimal point. The last ³ "0" or the period ³
³ E ³ digit printed is rounded. ³ appears without a ³
³ ³ ³ number following it, ³
³ ³ ³ no decimal point is ³
³ ³ ³ printed. ³
ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ g ³ Precision specifies the maximum ³ All significant digits ³
³ G ³ number of significant digits ³ are printed. ³
³ ³ printed. ³ ³
ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ c ³ No effect. ³ The character is ³
³ ³ ³ printed. ³
ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ lc, C ³ No effect. ³ The "wchar_t" char- ³
³ ³ ³ acter is printed. ³
ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ s ³ Precision specifies the maximum ³ Characters are printed ³
³ ³ number of characters to be ³ until a null character ³
³ ³ printed. Characters in excess ³ is encountered. ³
³ ³ of precision are not printed. ³ ³
ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
³ ls, S ³ Precision specifies the maximum ³ "wchar_t" characters ³
³ ³ number of bytes to be printed. ³ are printed until a ³
³ ³ Bytes in excess of precision are ³ null character is ³
³ ³ not printed; however, multibyte ³ encountered. ³
³ ³ integrity is always preserved. ³ ³
ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
The printf function returns the number of bytes printed.
This example prints data in a variety of formats.
#include <stdio.h> int main(void) { char ch = 'h',*string = "computer"; int count = 234,hex = 0x10,oct = 010,dec = 10; double fp = 251.7366; printf("%d %+d %06d %X %x %o\n\n", count, count, count, count , count, count); printf("1234567890123%n4567890123456789\n\n", &count); printf("Value of count should be 13; count = %d\n\n", count); printf("%10c%5c\n\n", ch, ch); printf("%25s\n%25.4s\n\n", string, string); printf("%f %.2f %e %E\n\n", fp, fp, fp, fp); printf("%i %i %i\n\n", hex, oct, dec); return 0; /**************************************************************************** The output should be: 234 +234 000234 EA ea 352 12345678901234567890123456789 Value of count should be 13; count = 13 h h computer comp 251.736600 251.74 2.517366e+02 2.517366E+02 16 8 10 ****************************************************************************/ }Related Information