Printf parameter Summary

Source: Internet
Author: User

Source: printf parameter Summary

The format description string "is composed of a series of" format conversion specifiers ". The format conversion specifiers are described as follows:
% [+] [-] 0 m [. N] [output accuracy] <formal letter>
(1) form letters: Specify the output format, such as a table
D: decimal integer
I: decimal integer
X: hexadecimal integer
O: octal integer
U: Unsigned decimal integer
C: A single character;
S: String
E: exponential floating point number
F: Floating Point Number in decimal form
G: A shorter ratio of E and F
P: display the memory address of the Variable
N: It does not pass the formatting information to printf (), but enables printf () to put the total number of characters output by itself into the corresponding variable element
In the integer
%: Symbol % itself;
(2): If the output accuracy is D, X, O. U, the following two types of precision can be specified:
L: Long output precision
H: Short output precision
Int type precision by default
For example: long x = 123454578; printf ("% d", X );
If the formal letters are E, F, and G, the value of L is set to double instead of float;
(3): m [. N] specifies the output length. If the output is an instance, M indicates the total length of the output string, and N indicates the decimal part.

Character length, such as float x = 4.56; printf ("% 7.4f", X );
(4) 0: enter 0 for the unspecified empty position and 0 for the shareholding. the unused position is blank. This item is only available for output to the branches.

To specify, do not specify the string output. For example
Int x = 234;
Printf ("% 05d", x); // 00234
Printf ("% 5d", x); // *** 234
(5) [+] [-]: Specifies the output position. If + is specified or the default value is right-aligned, if-is left-aligned;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.