The basic course of C language (iii) input and output functions and control flow statements (2)

Source: Internet
Author: User
1. Format the specified character
The format specifier provided by the Turbo C2.0 is as follows:
━━━━━━━━━━━━━━━━━━━━━━━━━━
Symbolic effect
──────────────────────────
%d decimal signed integer
%u decimal unsigned integer
%f floating-point numbers
%s string
%c single character
The value of the%p pointer
Floating point numbers in the form of%e exponent
%x, int without symbol in hexadecimal notation
%0 An integer that is unsigned as octal
%g automatic selection of appropriate notation
━━━━━━━━━━━━━━━━━━━━━━━━━━
Description
(1). You can insert a number between "%" and a letter to indicate the maximum field width.
For example:%3d represents an output 3-bit integer and is not 3-bit right-aligned.
%9.2F represents a floating-point number with an output field width of 9, where the decimal digit is 2, the integer digit is 6, the dot is one digit, and the 9-bit right alignment is not enough.
%8s represents a 8-character string that is not 8 words Fu Yi aligned.
If the length of the string, or the integer number of digits exceeds the field width of the description, it will be output at its actual length. However, for floating point numbers, if the integer partial digits exceed the indicated integer digit width, the actual integer digits are output; if the fractional digit number exceeds the indicated decimal width, the output is rounded by the width of the description.
In addition, if you want to add some 0 before the output value, you should add a 0 to the presence width.
For example,%04d indicates that when outputting a value less than 4 digits, the front complement of 0 will make the total width 4 bits.
If you use floating-point numbers to represent the output format for characters or integers, the digits after the decimal point represent the maximum width, and the digits before the decimal point represent the minimum width.
For example,%6.9s represents a string that is not less than 6 and not greater than 9. If greater than 9, the contents of the 9th character will be deleted.
(2). You can add a lowercase letter L between "%" and a letter to indicate the length of the output.
Example:%ld indicates output long integer
%LF indicates output double floating-point numbers
(3). You can control the output left or right alignment, that is, add a "-" sign between "%" and the letter to indicate that the output is left-aligned or right-aligned.
For example:%-7d indicates output 7-bit integer left-aligned
%-10s indicates output 10 characters left-aligns alignment

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: info-contact@alibabacloud.com 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.