C language Complete Notes __c language

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise control characters function definition function prototype logical operators string format

The character set of the C language

The C language character set consists of letters, numbers, spaces, punctuation, and special characters.

1. Letter

Small Letter A~z Total 26

Capital Letter A~z Total 26

2. Digital

0~9 a total of 10

3. Blank character

Spaces, tabs, line breaks, etc. are collectively known as whitespace characters. Whitespace characters only work in the character constants and string constants. When they appear elsewhere, they are only spaced, and the compiler ignores them. Therefore, the use of whitespace in the program does not affect the compilation of the program, but the appropriate place in the program to use whitespace will increase the clarity of the program and readability.

4. Punctuation and special characters

27 Special Characters: +-*/=:;? \ ~| ! #% & () [] ^ <> _,. "' Space

Rules to follow when writing a program 1.10

1. One statement or one line.

2. The part enclosed by {} usually represents a hierarchy of programs. {} is generally aligned with the first letter of the structure statement and occupies a single row.

3. A lower-level statement or description can be written with a plurality of cells indented at a level of statement or description. In order to look clearer and increase the readability of the program.

1.8 input and output functions scanf and printf,

Commonly used escape characters and their meanings

Escape character

The meaning of the escape character

ASCII code

\ n

Carriage return Line Change

10

\ t

Jumps horizontally to the next tab position

9

\b

Backspace

8

\ r

Enter

13

\f

Walk Paper Change page

12

\\

backslash character "\"

92

\'

Single quotation mark character

39

\”

Double quote character

34

\a

Ringing Bell

7

\ddd

The characters represented by the number of 1~3 bits octal

\xhh

The character represented by the 1~2 bit hexadecimal number

Operators and expressions

The C-language operators can be grouped into the following categories:

1. Arithmetic operators: For all kinds of numerical operations. Including plus (+), minus (-), multiply (*), in addition to (/), residual (or modulo operation,%), self-increase (+ +), self-reduction (-),-(take negative) a total of eight kinds.

Note: A: In addition to the operator/requirement two operands (dividend and divisor), where the divisor cannot be zero, and when two integers are divided, their result must be an integer. If 7/2 results are 3.

B: The remainder operator can only be a certificate or an integer variable on either side. If the 18%7 value is 4. Flexible use of% and operators makes it easy to take single-digit digits of an integer (to 10) or to remove a single integer (divisible by 10)

C: The self-increasing operator + + and the self-subtraction operators-are all monocular operators. If the operator is placed in front of the variable, it is called the predecessor operation, and vice versa.

++i OR-I predecessors

i++ or i--rear

The preceding operation is the value of a variable that first adds one or minus one, and then participates in the operation of an expression. A post operation is a variable that first participates in an expression, and then one or minus one

2. Relational operators: For comparison operations. Includes six species greater than (>), less than (<), equal to (= =), greater than or equal (>=), less than or equal (<=), and not equal to (!=).

3. Logical operators: for logical operations. including with (&&), or (| |), NON (!) Three species.

4. Bitwise operator Operator: The amount of the participating operation, which is calculated by bits. Includes bits and (&), bits or (|), bits (~), bitwise XOR, or (^), left (<<), right Shift (>>) six kinds.

5. Assignment operators: For assignment operations, divided into simple assignment (=), compound arithmetic Assignment (+=,-=,*=,/=,%=) and compound bit operation Assignment (&=,|=,^=,>>=,<<=) Three class total 11 species.

The general form of composing a compound assignment expression is:

Variable Binocular operator = expression

It is equivalent to

variable = variable operator expression

For example:

A+=5 equivalent to A=a+5

X*=y+7 equivalent to x=x* (y+7)

R%=p equivalent to r=r%p

Compound assignment This type of writing, may not be accustomed to beginners, but very conducive to the compilation process, can improve the efficiency of compiling and produce high quality target code.

6. Conditional operator: This is a three-mesh operator for conditional evaluation (?:).

7. Comma operator: Used to combine a number of expressions into an expression (,).

8. Pointer operator: for content (*) and address (&) two operations.

9. Byte count operator: Used to calculate the number of bytes (sizeof) that the data type occupies.

10. Special operators: with brackets (), subscript [], members (→,.) and several.

4.5.1 printf function (format output function)

The printf function is called the format output function, and the last letter F of the keyword is formatted. The function is to display the specified data to the monitor screen in the format specified by the user.

"%d" indicates a decimal integer output;

"%ld" indicates a decimal-length integer output;

"%c" indicates a character-type output, and so on.

2. The format string in Turbo C in the general form of the string is:

Sign [Output minimum width] [. Precision] [Length] Type

The items in square brackets [] are optional.

The meaning of the items is described below:

1 type: The type character is used to represent the type of output data, and its format character and meaning are shown in the following table:

Format characters

Significance

D

Output signed integer in decimal (positive not output symbol)

O

Output unsigned integers in eight (not output prefix 0)

X,x

Output unsigned integers in 16 (no output prefix ox)

U

Output unsigned integers in decimal form

F

Output single or double real numbers in decimal form

E,e

Output single and double precision real numbers in exponential form

G,g

Output single, double precision real numbers in shorter output widths in%f or%e

C

Output single character

S

Output string

2) Logo: The symbol character is-, +, #, space four, the meaning of the following table shows:

Sign

Significance

-

Results left-aligned, right blank

+

Output symbol (plus or minus)

Space

The output value is positive with a space and a minus sign when negative

#

Has no effect on the C,s,d,u class; for class O, prefix o on the output, prefix the X class with 0x when the output is given, and a decimal point for the E,g,f class when the result has a decimal number

3 Output minimum width: decimal integer to indicate the minimum number of digits of the output. If the actual number is more than the defined width, the actual number of digits is output, if the actual number is less than the defined width, a space or 0 is filled.

4 Precision: Precision format character with "." The beginning followed by a decimal integer. The meaning of this item is: If the number is output, the number of digits, if the output is a character, the number of output characters, if the actual number of digits is greater than the defined number of precision, then truncate the more parts.

5. Length: The length format character is h,l Two kinds, h means to output by the short integer quantity, l represents the output by the long integer type.

4.5.2 scanf function ( format input function )

1. The general form of the scanf function the scanf function is a standard library function whose function prototype is in the header file "Stdio.h", the same as the printf function, and the C language allows you to not include stdio.h files before using the scanf function.

The general form of the scanf function is:

scanf ("Format control string", Address table column);

2. The general form of the format string format string is:

%[*][input data width] [length] Type

The items with parentheses [] are optional. The meaning of the items is as follows:

1 type: The type that represents the input data, and its format character and meaning are shown in the following table.

Represents the type of input data whose format character and meaning are shown in the following table.

Format

Character meaning

D

Enter decimal integer

O

Enter octal integer

X

Enter a hexadecimal integer

U

Enter an unsigned decimal integer

F or E

Enter real number (in decimal form or exponential form)

C

Enter a single character

S

Input string

2) "*" character: to represent the entry, read in and do not give the corresponding variable, that is, skip the input value. Such as:

scanf ("%d%*d%d", &a,&b);

When entered as: 1 2 3 o'clock, assign 1 to a,2 is skipped, 3 gives B.

3 Width: Specifies the width of the input (that is, the number of characters) with a decimal integer.

For example:

scanf ("%5d", &a);

Input: 12345678

Assign only 12345 to variable a, and the remainder is truncated.

Another example:

scanf ("%4d%4d", &a,&b);

Input: 12345678

will give 1234 to a and 5678 to B.

4 Length: Length format character l and h,l represent input long integer data (such as%ld) and double-precision floating-point numbers (such as%LF). h indicates the input of short integer data.

The following points must also be noted with the scanf function:

1 The SCANF function has no precision control, such as: scanf ("%5.2f", &a); it's illegal. You cannot attempt to enter a decimal number of 2 digits with this statement.

2 The variable address is required in scanf, if given the variable name, there will be an error. If scanf ("%d", a); is illegal, should be changed to Scnaf ("%d", &a);

3 when entering multiple numeric data, if the format control string does not have unformatted characters for the interval between the input data, you can use space, tab or carriage return for the interval. C compilation is considered to end when it encounters a space, TAB, carriage return, or illegal data (such as an illegal data when "%d" is entered "12A").

4 when entering character data, if the format control string is nothing more than format characters, it is considered that all characters entered are valid characters.

4.4.1 Putchar function (character output function)

The Putchar function is a character output function that outputs a single character on the monitor.

Its general form is:

Putchar (character variable)

For example:

Putchar (' a '); (output capital Letter a)

Putchar (x); (Output character variable x value)

Putchar (' \101 '); (also output character a)

Putchar (' \ n '); (Line Wrap)

Controls are performed on control characters and are not displayed on the screen.

You must use the file to include the command before using this function:

#include <stdio.h>

Or

#include "stdio.h"

4.4.2 GetChar function (keyboard input function)

The function of the GetChar function is to enter a character from the keyboard.

Its general form is:

GetChar ();

A character variable is usually assigned to an input character, which forms an assignment statement, such as:

char c;

C=getchar ();

There are several issues to be aware of using the GetChar function:

1 The GetChar function can only accept a single character, and the input number is also processed by character. When you enter more than one character, only the first character is received.

2 You must include the file "Stdio.h" before using this function.

3 in the TC screen run with this function program, will exit the TC screen into the user screen waiting for user input. Enter the finish and return to the TC screen.

4 The last two lines of the program can be replaced by either line of the following two lines:

Putchar (GetChar ());

printf ("%c", GetChar ())

4 simplest C programming-sequential programming

The execution part of the C program is made up of statements. The function of the program is also implemented by executing the statement.

The C statement can be grouped into the following five categories:

1) Expression statement

2) Function Call statement

3) Control statements

4) Compound statement

5) NULL statement

1. Expression statement: An expression statement consists of an expression plus a semicolon ";".

Its general form is:

An expression;

Executing an expression statement is a value that evaluates an expression.

For example:

X=y+z; Assignment statement;

Y+z; Addition Operation statement, but the calculation results can not be retained, no practical significance;

i++; Self-Added 1 statement, I value increased by 1.

2. Function Call statement: By the function name, the actual parameter plus semicolon ";"

Its general form is:

function name (actual parameter table);

Executing a function statement is calling the function body and assigning the actual parameter to the formal parameter in the function definition, and then executing the statement in the body of the function being called to find the function value (described in detail in the following function).

For example:

printf ("C program"); Call library function, output string.

3. Control statements: Control statements used in the process of controlling the program to achieve a variety of structural methods. They consist of a specific statement definition character. C language has nine kinds of control statements. Can be divided into the following three categories:

1 Conditional Judgment statement: If statement, switch statement;

2 loop Execution statement: Do While statement, while statement, for statement;

3) Turning statement: Break statement, Goto statement, continue statement, return statement.

4. Compound statement: A statement consisting of multiple statements enclosed in parentheses {} is called a compound statement.

Compound statements should be considered as a single statement rather than multiple statements in a program.

For example:

{x=y+z;

A=b+c;

printf ("%d%d", x,a);

}

is a compound statement.

Each statement within a compound statement must be separated by a semicolon ";" At the end, you cannot add a semicolon outside the bracket "}".

5. NULL statement: Only the semicolon ";" statement is called an empty statement. An empty statement is a statement that is not executed. In the program The Hollow statement can be used as an empty loop body.

For example

while (GetChar ()!= ' \ n ')

;

The function of this statement is to re-enter it as long as the character entered from the keyboard is not a carriage return.

The loop body here is an empty statement.

5.3 If statement

Three types of 5.3.1 if statements

1. The first form is the basic form: if if (expression) statement

The semantics is that if the value of the expression is true, the following statement is executed, otherwise the statement is not executed.

2. The second form is: If-else if (expression)

Statement 1;

Else

Statement 2;

The semantics are: if the value of the expression is true, execute statement 1, or EXECUTE statement 2.

3. The third form is the If-else-if form of the first two forms of the IF statement generally used in the case of two branches. When you have more than one branch selection, you can use the IF-ELSE-IF statement, which is the general form:

if (expression 1)

Statement 1;

ElseIf (expression 2)

Statement 2;

ElseIf (expression 3)

Statement 3;

...

ElseIf (expression m)

Statement m;

Else

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.