A basic unit of C language-function. 1 . main(); ② Library function; 3. Custom function. ABC();
Composition of two functions: 1. The header of the function and the first line statement of the function (including return value type, function name, function parameter type and function parameter name). () cannot be omitted, for example: void main() 2. Function body, including the declaration part of the function (declaring the function to be used in the program), the definition part (defining the variables that the function may use) and the execution part (used to realize the function of the function).
Semicolons that are indispensable for three functions.
Four input and output functions: scanf, getchar, gets, printf, putchar, puts, etc.
Note 5: It cannot be nested. Exercise 18 on page 94.
Case sensitivity: the difference between Printf and printf.
7. Computer processing of C language: editing (. c)——& gt; Compile (. obj)->; Connect (. exe)->; The result of running.
Eight c program execution starts with the main () function and ends with the main function.
Decimal conversion: focus on mastering decimal, octal and hexadecimal and their mutual conversion, as well as the original complement (using bit operation).
User defined identifier: 1. Letters, numbers and underscores. The first letter cannot be a number. 3. It can't be the same as the keyword defined by C language, but it can be the same as the predefined identifier.
1 1 constants:
1 Integer constants Decimal, Octal (starting from 0) and Hexadecimal (starting from 0x) have no negative numbers.
2 Real constant 2.78 (there must be a number on at least one side after the decimal point) 5.48e-3 (there must be a number before e and an integer after e).
3-character constant a. Universal character' a'; B. escape characters: universal escape characters and octal \ hexadecimal escape characters. \n ',' \\ ',' \t ',' \ ',' \64 ',' \82 ',' \x42 ',' \xff ',' a 12 '。
4 string constants "a" and "a"
Twelve variables 1. Must be defined before use; 2 variables, 3 elements, variable type, variable name and variable value.
Example 1: The following is A. 02 B. 0 C.038 D.0xAL, which is not the plastic constant of C language.
Example 2: The legal real number constant is a.5e2.0b.e-3c.2e0d1.3e.
Example 3: If there is a statement char a;; ; In order to assign the character A to the variable A, the following correct assignment expression is
" a" B.a='a' C.a="97" D.a='97 '
Example 4: The following legal definitions are:
A.float _ a = 1. 1e- 1; B. double b =1+5e2.5; C.long do = 0xfdaLd . float 2 _ and = 1-e-3;
Thirteen. Principle of remainder: 1. Both sides should be integers;
2. First, find the absolute value of the remainder, which has the same sign as the dividend. Please pay special attention to the difference between "%"and "/". - 10/3 10/-3
14. Assignment operators and expressions: the operation sequence is from right to left, and the left side must be a variable (which can hold things).
A=b=c= 10 (this cannot be done by definition); x+y = 10; x+ 1 = 10;
15. Comma expression: a=(b=5, b+10); b=(a=4*9,a*2),a-3; Consider priority.
Sixteen. Type conversion char a =' aint b = 32 floating c = 32.5 double s, d = 32s = a+b+c+d;
Seventeen. Forced type conversion floating b = 3.5int a;; a =(int)b;
Example 5: set int x =11; The value of the expression (x++* 1/3) is a 3 B 4.
Example 6: Int A = 1, B = 1, c =1; a = a+++b+++c; The final values of a, b and c are: a = 4;; b = 2; c = 1;
Example 7: There are the following definitions and sentence groups: float x =1; int y = 2; y+= ++ x * ++ x; The final value of y is: 1 1.
Example 8: int x = 2; printf("%d ",((x=4*5,x*5),x+25)); 45
Example 9: If the variable has been correctly defined and assigned, the following expression that conforms to the syntax of C language is
a . a:= b+ 1 b . a = b = c+2 c . int 18.5% 3d . a = a+7 = c+b
Eighteen input and output formats ch = getchar (); putchar(ch); Scanf("%d%f%c ",& i, & ampb & amp;; c); printf("%d,%d ",a,b);
Example 10: There are the following programs, and the output results are as follows
main(){ int a; char c = 10; float f = 100.0; Double x;
a = f/= c * =(x = 6.5); printf(" % d % d % 3. 1f % 3. 1f \ n ",a,c,f,x); } 1 65 1.5 6.5 (problem set 2. 13)
Nineteen. Logical operation and its short circuit phenomenon (used for logical AND and logical OR)
20. The priority of relational operators and expressions a>b>c should be clear (i.e. off > logic).
2 1. conditional operator and expression a>b? A: c & gtD:c:d equivalence and a>b? A: (c>d? C:d) let A = 1, B = 2, C = 3 and D = 4;; four
Example 1 1: The output of the following program is a.d = 0c = 50b.d = 0c = 2c.d =1c = 50d.d =1c = 2.
main(){int a=3,b=4,c=2,d; d = a & lt! b & amp& amp(c=50)>b; printf("d=%d c=%d ",d,s); }
22. example of if statement 12: the output of the following program is
int i= 1,j= 1,k = 2; if((j++ | | k++))& amp; & ampi++) printf("%d,%d,%d\n ",I,j,k); 2,2,2
If-else statement Note: Only one statement can be managed after if.
main(){int a=2,b=- 1,c = 2; If (a<b) if (b & lt0)c = 0;;
else c++; printf("%d\n ",c); }
23. The output of the program under the 23.switch statement is: main(){int x= 1, a=0, b = 0;;
Switch (x){ Case 0: b++; Case1:a++; Case 2: a++;+; b++; } printf("a=%d,b=%d\n ",a,b)} a=2,b= 1
24.while vs do-while
Master ()
{int i=0,n = 0;
And (n! = 0){ i++; ++i} printf("%d ",I);
}
Master ()
{int i=0,n = 0;
do { i++; ++i} while(n! =0); printf("%d ",I);
}
25-minute break vs continue
Note: the break statement can only appear in the loop body and switch statement, and the continue statement only appears in the loop.
Master ()
{int sum,I; sum = 0; for(I = 10; I>0; I-){ if(I & gt; 5) continue; sum = sum+I; } printf("%d\n ",sum); }
Example 13: The output of the following program is: main(){int a, y; a = 5; y = 0; a=7 y=7
do { a+= 2; y+= a; printf("a=%d y=%d\n ",a,y); If (y> 10) is broken; } while(a = = 7); }a=9 y= 16
Example 14: The output of the following program is: main(){int k=4, n = 0;; for(; n & ltk; ){ n++; if(n%3! =0) Continue; k-; }
printf("%d,%d\n ",k,n); } 3,3
26. Definition, initial value and reference of one-dimensional array. Note: int a [10] = {0}; Constant expression in parentheses, with subscripts starting from 0. Example 15: if defined, float y[5]={ 1, 2,3}; Then the following description is correct: ()
A.y does not represent an array element B. When defining this array, the width of the array is not specified, and the definition effect is the same.
C. the array contains three elements, and the value of D.A. [3] is 3.
Example 16: The output of the following program is: main(){int z, y [3] = {2,3,4}; z = y[y[0]]; printf("%d ",z); } 4
Example 17: the output of the following program is: main () {int p [7] = {11,13, 14, 15,15.
While (I<7&& [i]% 2) {k = k+p [i]; i++}printf("%d\n ",k); } 24
Example 18: The output of the following program is:
main(){int n[5]={0,0,0},I,k = 2; for(I = 0; I & ltk;; i++)n[I]= n[I]+ 1; printf("%d\n ",n[k])} 0
27. Definition, initial value and reference of two-dimensional array
Example19: main () {int a [3] [3] = {{1,2}, {3,4}, {5,6}}, i, j, s = 0;; for(I = 1; I<3; i++)
for(j = 0; j & lt= I; j++)s+= a[I][j]; printf("%d\n ",s)} 18
Example 20: The following two-dimensional array cannot be defined correctly:
A int a[2][2]={{ 1},{ 2 } }; B int a[][2]={ 1,2,3 }; C int a[2][2]={{ 1},2,3 }; D int a[2][]={{ 1,2},{3,4 } };
Example 2 1: if a is an array with m rows and n columns, then a[i][j] is the () th element of the array.
a I * m+j B I * m+j+ 1 C I * n+j D I * n+j+ 1
Definition, initial value and reference of 28-character array
1.char arr[ 10]={'h ',' e ',' l ',' l ',' o ' }; 2.char arr[]={'h ',' e ',' l ',' l ',' \ 0 ' };
3 . char arr[ 10]= { " hello " }; 4 . char arr[ 10]= " hello ";
Twenty-nine strings input and output if charstr [10] = "hello ",arr [10] =" me ";
scanf("%s ",str); printf("%s ",str); gets(str); Sell (str);
strcpy(arr,str); strcmp(str,arr); strlen(str); strcat(str,arr);
Example 22: The output of the following program is:
main(){ char ST[20]= " hel \ 0lo \ t "; printf("%d%d\n ",strlen(st),sizeof(st))} 3,20
Example 23: The output of the following program is: char s [] = "\ \141\141ABC \ t"; printf("%d\n ",strlen(s)); nine
Thirty pointers and the string char * a;; A= "hello"; char a[ 10]; A= "hello";
Example 24: The correct sentence group in the following options is: () a.chars [8]; S={ "Beijing"};
b . char * s; S={ "Beijing"}; c . char s[8]; S= "Beijing"; d . char * s; S= "Beijing";
Declaration, definition and call of parameter function.
Float add (floating point x, floating point y); /* Function declaration */
Mai ()
{int a=3.5,b=4.0,d;
d=add(a,b); /* Function call */
}
Float add(float x, float y)/* function definition */
{ return x+y; }
Nested calls and recursive calls of 32 functions
Double fun 1 (double a) {return a * = a; }
Double fun2 (double x, double y)
{double a=0, b = 0;;
a = fun 1(x); b = fun 1(y);
return(int)(a+b); }
Master ()
{double w; w=fun2( 1. 1,2.0);
printf("%f\n ",w); }/* Nested call */
Long fiber (integer)
{ if(n & gt; 2) return (fib (n-1)+fib (n-2));
Otherwise, return 2; }
main(){printf("%d\n ",fib(3)); }/* Recursive call */
Value transfer and address transfer in 33 functions (no matter what is passed, it is essentially value transfer, and only one is address value transfer)
func(int a){ a = 100; } func(int a[]){ a[0]= 100; }
main(){ int a = 10; func(a); printf("%d ",a); } main(){ int a[ 1]; a[0]= 10; func(a); printf("%d ",a[0]); }
Thirty-four local variables and global variables: the storage types of local variables are divided into auto, register and static, in which the storage space of auto and register variables is dynamic and their values disappear as soon as the program ends. After the program ends, the value of the static variable still exists. Global variables are static variables.
int a = 5;
fun(int b){ static int a = 10; a++ = b++; printf("%d ",a); }
main(){ int c = 20; Fun (c); a++ = c++; printf("%d\n ",a); } 3025 What if you add a fun(c) to main? 305025
The 35 macro commands and files include
# Definition number 10
#define S(x) x*x/* Just put these three define statements in a file hong.h */
#define f(x) (x*x)/* Add a # include "hong.h" before the main function, and the running result of the program is the same */
main(){int i 1,I2; I 1 = 1000/S(N); I2 = 1000/f(N); printf("%d %d ",i 1,I2); } 1000 10
Definition, initialization and operation of 36 pointer variables
Master ()
int n=5,* p = & ampn; Printf ("Address: %d\n", p);
Printf ("data: %d\n", * p);
printf(" & amp; *p is: %d\n ",&* p);
printf(" * & amp; nis:%d\n ",* & ampn); }
Example 24: Define int n = 0, * p = &;; n; The correct assignment statement is: a.p =1; p=&。 n; Option A can't, because an address value is to be stored in P. For option B, because P has pointed to the storage unit N, it is actually equivalent to n=5.
Thirty-seven pointers and one-dimensional arrays
int a[ 10],* p; /*a is different from P, A is array name is constant, and a++ cannot be executed; A+= 1, and p can be */
p = & ampa[0]; p = a; /* These two statements are equivalent, both of which let the P pointer point to this array */
After executing the above statement: p[i] is equivalent to a [I]; *(p+i) is equivalent to *(a+i)
Thirty-eight pointers and two-dimensional arrays: The following are different ways to refer to the elements in row I and column J of two-dimensional arrays.
1.a[I][j];
2. because a[i] represents the first address of the I-th row, a[i]+j represents the addresses of the I-th row and the J-th column, and *(a[i]+j) represents the values of the I-th row and the J-th column.
3. Because a[i] can be written as *(a+i), the expression in 2 can be written as *(*(a+i)+j).
4. Change a[i] in 1 to *(a+i), and the following remains unchanged, which can be written as (*(a+i))[j].
Referencing a two-dimensional array through a row pointer
int a[4][4],(* p)[4]; p = a;
Referencing two-dimensional array elements through pointer array
int *p[4],a[4][4]; for(I = 0; I<4; i++)p[I]= a[I];
After the above two knowledge points are assigned as above, to refer to the elements of row I and column J, you only need to change A to P. ..
Forty-one function pointer and pointer function
int f(int x){……} main(){ int(* p)(); int a,b = 2; p = f; a =(* p)(b); a = f(b); a = p(b); ……}
Function pointer: a function whose return value is a pointer (address). int *func(int a,int b);
Example 25: int a [] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, * p = a, I; Where 0
A.a[p-a]b . *(& amp; a[I]c . p . d . a[ 10]
Example 26: If Int A [3] [2] is defined; The expression that can correctly represent the address of T array elements is A.&; a[3]b[2]a[3]c a[ 1]d . * a[2]
Example 28: The output of the following program is: A.69825b.63825c.53825d. 53886 . 68686866666
main(){char ch[2][5]={"6937 "," 8254"},* p[2]; int i,j,s = 0; for(I = 0; I<2; i++)p[I]= ch[I];
for(I = 0; I<2; i++)for(j = 0; p[I][j]& gt; '\0'; j+= 2)s = 10 * s+p[I][j]--0; printf("%d\n ",s); }
Definition and initial value of forty-two structures
Structure student {int num character name [10]; } *p, stu[2]={{ 123, "Zhang"}, {124, "Li"}}; p = stu
Typedef struct STUdent {} STU After this statement, you can use stu to define structural variables.
Example: Stu A, * p;; Equivalent to struct student a, * p;;
Reference 43 structural variables
printf("%d ",stu[ 1]。 num); printf("%d ",stu[ 1]。 Name); printf("%d ",p[ 1]-& gt; num);
printf("%d ",p[ 1]-& gt; Name); printf("%d ",stu); This is wrong.
For the operations of malloc, calloc, free function and linked list, see book p 120 int *p, *pint. float * q; p =(int *)malloc(sizeof(int)); q =(float *)malloc(sizeof(float)); pint=(int*)calloc( 10,sizeof(int)); Free (p); Exercise 12 Chapter 16.
Example 29: The following assignment statement is correct: structworker {int numchar * name} * p, a;
A.worker . num = 1; b . p . num = 1; c . * p . num = 1; d . a . num = 1;
Example 30: In the environment of 16-bit pc, the result of the following program is as follows: (You only need to be impressed with this question, and you don't need to delve into it)
Structure worker thread {int numchar * name} a;; Main () {printf ("%d ",sizeof (a))} 4 (8 for 32 bits).
Example 3 1: has the following definition: structss {charname [10]: intage: charsex:} stu [3], * p = stdThe following input statement is wrong: ()
A.scanf("%d ",& amp(*p)。 Age); B.scanf("%s ",& standard name); C.scanf("%c ",& standard [0]. Sex); D.scanf("%c ",& amp(p->; Sex));
Because std means address, and the address should not be like this, it should be&; (standard->; Name);
Forty-five-bit operation ~, < <, gt; & gt, |,& Example 5.4
46 file opening and file operation file * fpcharstr [10] = "hello"; int a,b;
1.if((fp=fopen("in.dat ","Rb ")= = NULL)printf ("Cannot open file!" ); /* Pay special attention to the way files are opened, especially the influence of "w", "r+", "w+" and "a" on files. */
2.fclose(FP); /* Close the file */feof (fp); /* Tests whether the file is completed, and returns 1 if it is completed, otherwise returns 0*/
3.fseek (FP, 12, seek _ set)/* Move the file pointer to the12nd byte behind the file start position */
4.fseek (FP, 12, seek _ end)/* Move the file pointer to the penultimate byte of the file */
5.fseek(fp, 0, SEEK_SET) /* Use the rewind(fp) */ function to move the file pointer to the beginning of the file.
6.fseek (FP, 12, seek _ end)/* Move the file pointer to the end of the file */
7.ftell(FP); ch = fgetc(FP); putc(ch,FP); fgets(str,n,FP); fputs(str,FP);
8.fscanf(fp, "%d%d", & 1, & b); /* The two numbers taken from the file pointed by fp are stored in A and B respectively */
9.fprintf(fp," %d%d ",a,b); /* Output (store) the data stored in A and B to the file pointed by fp */
10.fread(str,size,count,FP); /* Take the size*count bytes from the file pointed by fp and store them in the str array */
1 1.fwrite(str,size,count,FP); /* Store size*count bytes */
Are there any related books? This is some information I used in the exam that year! I hope it helps you! !