C-Language functions

Source: Internet
Author: User

Function:

Common functions:

printf functions:

Description: A function used to output information statements

Format: printf ("Format control string", output item list);

Format characters:

1):%d output decimal integer

%MD Setting the field width

M: can be positive or negative

If the number of bits to output is greater than M, the output is based on the actual field width

Otherwise m is greater than 0 and the left side is the complement; M is less than 0.

%0md

The less part uses 0 to fill the position

2):%f output A real type of data

%F displays 6 decimal places by default, and if the precision requires more than 7 bits, a double is used to store the real type with a precision of 15 bits

%m.nf

M: Indicates the total number of digits

N: Number of digits after the decimal point

%-6.2f minus indicates a complement from the right

3):%c outputs one character

4):%s outputs a string

5):%o Output a number in the form of a eight binary

6):%x outputs a number in the form of a 16 binary

7):%p Output an address (memory address)

scanf function: Blocking function

The scanf function is included in the standard "input Output" header file "stdio.h" for receiving keyboard input content

Format: scanf ("Format control string", entry address list);

Entry address lists: variable addresses that need to receive data, which correspond to the type and quantity of the format control string, separated by a "comma" between each address name when there are multiple entries, and: The output format and variable type are consistent (the address of a variable can be obtained by the address operator &)

scanf function Format Control character:

I enter a signed or unsigned decimal, octal, hexadecimal integer

U enter an unsigned decimal integer

F, e/e, g/g enter a floating-point number in decimal or exponential form

Note:%f this is possible,%m.nf this is not possible in the scanf

SCANF Precautions:

1.scanf function will end execution when it encounters a carriage return

2. When the value of a single variable is received, before entering the value, if we enter a space, carriage return, tab, will be ignored

scanf ("%d%d", &a,&b); Ask us to enter two integers when typing on the keyboard, separated by a space or carriage return

After entering the first number, if the middle input space, carriage return, TAB will be ignored

3.%*d where * represents skipping an integer

4.\n about scanf, try not to use \ n, if you accidentally use, enter the value of a random input, then you need to input \ n

scanf function Principle:

"Known Issues: shaping and character blending input"

%d%c%d

Operating principle:

1. When the user enters the content, the user input is stored in the input buffer of the scanf, then the CANF function will take its desired content from the input buffer according to the requirements of the format-controlled character, and if the buffer gets the content in accordance with our format requirements, then the value is stored in the variable If the format is inconsistent, the value of the variable is not modified

2. If there is content in the scanf buffer, then scanf will not prompt us to enter the content

    

recursive function/recursive invocation:

C-Language functions

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.