C language interview Basics

Source: Internet
Author: User
Printf functions:

The function that generates the formatted output (defined in stdio. h ). Output to Terminal (display, etc)

Usage:

  Int printf (const char * format, [argument]);

 

Format:% [Flags] [width] [. Perc] [f | n | H | L] Type

 

Specify the data output method as follows:

 

  1. TypeMeaning:

 

D signed 10-digit integer

 

I signed 10-digit integer

 

O unsigned octal integer

 

U unsigned 10-digit integer

 

X unsigned hexadecimal number, expressed in lowercase abcdef

 

X unsigned hexadecimal number, expressed in abcdef

 

F floating point number

 

E/E floating point in scientific format

 

G uses % F and % E to represent the smallest number of digits in the same g format as the floating point G, but expressed as an index.

 

C Single Character

 

S string

 

S wchar_t character (width) type string

 

% Display percentage itself

 

P shows a pointer, and the near pointer is expressed as: xxxx

 

Far pointer: xxxx: yyyy

 

N connection parameters should be a pointer, where the number of written characters is stored

 

  2. flagsSpecifies the output format. Values and meanings are as follows:

 

No right alignment. Fill in 0 and space on the left.

 

-Align left and fill in spaces on the right

 

+ Add the symbol + or-before the number-

 

0: Add 0 to the front of the output until the specified column width is filled (cannot be used together -)

 

If the output value of a space parameter is positive, it is preceded by a space.

 

# No effect on type = C, S, D, I, u

 

When type = O, X, X, add '0', "0x", "0x" before the value respectively"

 

Type = E, E, F, always use the decimal point

 

Type = G, G, the decimal point is always displayed except for the value 0

 

  3. WidthUsed to control the width of the displayed value. The values and meanings are as follows:

 

N (n = 1, 2, 3...) must be at least n characters in width.

 

0n (n =, 3...) must be at least n characters in width. If not, fill the left side with 0 characters.

 

* In the format list, the next parameter is still width.

 

  4. precUsed to control the number of digits after the decimal point. The values and meanings are as follows:

 

No display by default

 

0 when type = D, I, O, U, X, no effect

 

Type = E, E, F, do not display decimal point

 

N (n = 1, 2, 3...) the maximum number of decimal places when type = E, E, F

 

Type = others, indicating the maximum display width

 

. * In the format list, the next parameter is still width.

 

  5. f | n | H | LIndicates whether the pointer is a remote pointer or an integer is a long integer.

 

F remote pointer

 

N near pointer

 

H short integer or single-precision floating point number

 

L long integer or double-precision floating point number

Function return value:

The general form of the printf function is:

 

Int printf (const char * format, [argument]);

 

In the preceding format, enter "printf (" in Visual C ++ and you will see it.

 

The printf function is of the integer type, and its return value is of the integer type.

 

The value is the number of characters that printf controls output.

 

The printf () function outputs all parameters by character. According to the parameter 1 (const char * format) of the function, it is not hard to understand.

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.