The first chapter is an overview.
1 and basic knowledge of c language
1. 1, C language execution steps
Edit-program code input, generate source program *. c
Compile-syntax analysis for error detection, and translation of the generated object program *.obj.
Grammatical or logical errors, change from the first one, variable definition, statement format, expression format, etc. )
Link and assemble with other target programs or libraries to generate an executable program *.exe.
carry out
Basic knowledge and main functions of 1.2
Location of the main () function
C programs always start with the main () function.
A C program can contain a main function, namely the main () function; You can also include a main () function and several other functions.
Structure and C Program of 1.3
Functions and main functions
A program consists of one or more functions.
There must be one and only one main function, main ()
Program execution starts from main and ends at main, and other functions are executed by nested calls.
Program statement
C program consists of statements.
Use ";" As a statement terminator
To annotate ...
//
or
/* */is a comment and cannot be nested.
Do not generate compiled code.
1.4, C programming rules
Used to use lowercase letters, case-sensitive.
There is no line number, and there is no concept of program line: usually one statement takes up one line.
You can use blank lines and spaces.
Commonly used zigzag writing format; Statements in the same hierarchy are aligned up and down.
Chapter 2, Basic Data Types and Operations
2. 1, data type of C program
Pay attention to the different meanings of types and variables (types are fixed names and variables are named by themselves)
Storage space occupied by variables
data type
Basic types: integer type, character type and floating-point type (single precision type and double precision type)
Structure type: array type, structure type.
Pointer type
Empty type
Pay attention to the way of assigning initial values to basic types.
Representation of basic data types
Shaping data
Decimal system: start with a non-zero number, such as: 123, -9, 0.
Octal; Start with the number 0, such as 0 123067.
Hexadecimal: starts with 0x, such as 0x 123, 0xff.
Real data
Decimal: Decimal point must be entered, such as: 123.0, -9.0.
Exponential form; Such as: 1.23E3, 0.9e-2, 5e2.
character data
Ordinary characters: such as' a',' 2',' h',' #'
Escape characters: such as' \ n',' \ 167',' \ XLF', \ \
(To align several columns: specify the width. E.g.% 100 \' \ t' tab stop)
(String length. " ABC \ n \ t \ \ " strlen 6; Size 7)
Storage length of basic data type
integer
Int byte number 2 digits 16 digits expression range -32768-32767.
Short 216-32768-32767
Long 432-2147483648-2147483647
Real type
Floating 4 32 3.4e-38-3.4e38
Shuang 8 641.7e-308-1.7e308
Character; Role; letter
char 1 8- 128- 127
2.2, identifier naming rules
Naming rules of C language identifiers
Identifiers consist of numbers, letters and underscores.
The first character of the identifier must be a letter and an underscore.
In C language, identifiers cannot be reserved words (keywords).
For example, the automatic external size of floating-point static case of structural char goto switch continues in typedef const if union default long unsigned do register void double return else short while enumsigned.
Arithmetic operator+-*/%
Relational operator >; & lt= = & gt= & lt= ! =
Logical operator! & amp& amp||
positional operator
Assignment operator = and its extended assignment operator
Conditional operator? :
Comma operator,
Pointer operator *&;
Byte number operator sizeof
Forced type conversion operator (type)
Component operator. -& gt;
Subscript operator []
Others such as function call operator ()
Operator priority
From high to low: monocular operator, arithmetic operator, relational operator and assignment operator.
Description: Monocular operators: self-increasing operator, self-decreasing operator, type substitution operator. Combination direction: from right to left
For example+++-i first-i.
The combination direction of arithmetic operation is from left to right.
2.3 Basic operations and expressions
Relational expressions and logical expressions
(a>b) and amp&(x>y) (a = = b) || (x = = y)! = a | |(a & gt; b)
A & b.a is 0. B not implemented.
A||b a is 1. B not implemented.
The logical operation result in C: 1 stands for "true" and 0 stands for "false";
Judging whether an expression is true or not: 0 means "false" and non-0 means "true"
Conditional expression comma expression
For example, k=5, k++
The comma value is 5; K is 6.
The expression 1? Expression 2: Expression 3
K = 5 & gt6 ? 1 : 0
2.4. Data type conversion of mixed operation
2/3+0.5 double precision floating-point type
Chapter 3, Sequence Structure Programming.
3. 1, C sentence classification
simple statement
Expression statement expression+semicolon
An empty statement with only semicolons.
Compound statements enclose several statements in curly braces.
Process control statement
Select statement if, switch
Loop statements while, do while, for
Transfer statement break, continue, return goto
3.2. Format input function scanf
Universal format: scanf ("format control string", address list);
When using the scanf function, you need to pay attention to:
The number of format characters must be the same as the number of input items, the data type must be one-to-one, and the unformatted string (descriptive) should be completely input.
When entering execution data, you can enter integer data without decimal point.
When numeric data is mixed with characters or strings, you need to pay attention to the input method.
3.3. Format output function printf
Printf ("format control string", output list);
Specifies the output format, which consists of format string and unformatted string, and the unformatted string is output as it is.
%[Flag] [minimum output width] [. Accuracy] [Length] type
Logo:-Left alignment; +right alignment;
%f,%d,%c,%s
3.4. Other input and output functions
Putchar getchar puts gets
Chapter four, select structure programming.
If selection structure
Single branch
If (expression)
sentence
Double branch
If (expression)
Statement 1
other
Statement 2
Multi-branch
If (expression 1)
Statement 1
Else if (expression 2)
Statement 2
. . .
Else if (expression m)
Statement m
other
Statement n
Switch (expression)
{
Case constant expression 1: statement1; Break;
Case constant expression 2: statement 2; Break;
. . .
Case constant expression m: statement m; Break;
Default value: statement n; Break;
}
Pay attention to break
Chapter five, the program design of circular structure.
Three elements of circulation
Initial conditions; Termination conditions; Do something repeatedly between the initial condition and the termination condition (loop body)
While (emoticon)
sentence
do
sentence
While (emoticon);
For (the initial value assigned to the loop variable; Cyclic conditions; Cyclic variable increment)
(for(); // ; Execution time delay. Used for information exchange and so on. For example, for (I = 0, I
Break statement: it cannot be used for any other statement except loop statement and switch statement; Jump out of the loop.
Continue statement: skip the remaining statements in the loop body and force the next loop; Jump out of this cycle.
Chapter 6, Functions and Compilation Pretreatment
6. Definition and Call of1.Function
Type Identifier Function Name (Parameter Table)
Statement part
sentence
}
Example:
Int max (int x,int y)
{ int z; & ltbr & gtZ = x & gty? x:y; & ltbr & gt returns (z); }
6.2, local variables and global variables
Pay attention to the definition and use of static variables in functions.
6.3, variable storage type
Storage type of local variables
Automatic variable (automatic) dynamic storage
Static storage of local static variables
Static storage of register variables.
Storage type of global variables
Automatic variable (automatic) dynamic storage
Static storage of external variables
Global static static storage
External external reference
Static cannot be referenced externally.
Chapter 7, Array
7. 1, the definition and use of one-dimensional array
Special attention should be paid to the initial value and termination conditions of the circulating body.
Example:
Master ()
{
Int I,a[ 10];
for(I = 0; I < = 9; i++)
a = I;
for(I = 9; I & gt=0; I-)
Printf("%d ",a);
}
Pay attention to the subscript problem
7.2, the definition and use of two-dimensional array
Initialization of two-dimensional array
For example:
Int a[3][4]={{ 1,2,3,4},{5,6,7,8},{9, 10, 1 1, 12 } };
Int a[3][4]={ 1,2,3,4,5,6,7,8,9, 10, 1 1, 12 };
Int a[ ][4]={ 1,2,3,4,5,6,7,8,9, 10, 1 1, 12 };
Int a[ ][4]={{ 1,2,3,4},{5},{9, 10, 1 1, 12 } };
For example: int a[3][3]={{ 1}, {2}, {3}};
Is to assign values to the elements in the first column of each row, and the unassigned elements take 0.
7.3. Character arrays and strings
Process a string with a character array and use the closing tag' \ 0'.
Such as: char c [] = {"I am very happy"};
Initializes a character array with string constants.
Char c[ ]={'I ',' ',' a ',' m ',' ',h ',' a ',' p ',' p ',' y ',' \ 0 ' };
Chapter 8, Pointer
8. 1, the concept of address and pointer
int I;
Int * i _ point
8.2. Pointer variables and variable addresses
Operator: *&;
8.3, pointer and one-dimensional array
If there is a definition.
int a[ 10];
int * p = a;
Analyze the meaning of the following expressions:
One,&one,
*(a+i),a+i,
*(p+i),p+i
A=*(a+i)=*(P+i)
& ampa=a+i=p+i
8.4. Pointers and strings
Master ()
{
Char string[ ]= "I love China!" ;
Printf("%s\n ",string);
}
Master ()
{char *string= "I love China!" ;
Printf("%s\n ",string);
}
8.5, pointer variables as function parameters
Definition of formal parameters; The form of true argument; How parameters are passed.
Chapter 9, Structure
9. 1, Definition of Structure Types and Variables
Structure name
{Member list};
Structural students
{ char stno[8]; & ltbr & gtchar name[20]; & ltbr & gt charming sex; & ltbr & gtInt age& ltbr & gt floating score; & ltbr & gtchar addr[30]; & ltbr & gt};
student
{ char stno[8]; & ltbr & gtchar name[20]; & ltbr & gt charming sex; & ltbr & gtInt age& ltbr & gt floating score; & ltbr & gtchar addr[30]; & ltbr & gt};
Stu 1, stu2, structural students
9.2. References to structural variables
The general form is:
Structure variable name. Member name
9.3. Structure array
Structure array structure array elements. Member name
Pointer variable to structure
(*p)。 Member name
p->; Member name
other
Strcpy (character array 1, string 2)
Strcat (character array 1, character array 2)
Strcmp (string 1, string 2)
Character array