C Language Review Materials for Final Exam Practice Questions and Answers Mind Map
Copy the link to open and save in the browser: https://pan.xunlei.com/s/VOF4bIaPe4XAqG0QOjWDdY1qA1?pwd=ajyh#
20. Data Input
1) scanf(“a=%d,b=%d”,&a,&b) is a super important exam point!
It is essential to remember that data must be entered in the terminal in the format of the first part. The core of the exam is: exactly the same.
The input on the black screen must be a=12,b=34 to correctly assign 12 and 34 to a and b. Any slight difference will not work.
2) scanf(“%d,%d”,x,y); this writing is absolutely incorrect, the second part of scanf must be an address! scanf(“%d,%d”,&x,&y): note that it must be written this way to work!
3) Special attention to pointers in scanf examination
For example: int x=2; int *p=&x;
scanf(“%d”,x); incorrect scanf(“%d”,p): correct scanf(“%d”,&p): incorrect scanf(“%d”,*p) incorrect
4) Specify the length of input
Terminal input: 1234567
scanf(“%2d%4d%d”,&x,&y,&z); x is 12, y is 3456, z is 7. Terminal input: 1234567. Since there is a space between 1 and 2, only 1 digit is assigned to x scanf(“%2d%4d%d”,&x,&y,&z); x is 1, y is 2345, z is 67
5) Additional notes:
a) Format examination of scanf function:
Note that the second part of this function is &a, not a; scanf(“%d%d%*d%d”,&a,&b,&c); skips the input of the third data.
b) Examination of putchar, getchar functions:
char a=getchar(); (O has no parameters, it gets one character you input from the keyboard into variable a). putchar(‘y’) outputs the character y to the screen.
c) How to swap the values of two variables x, y (must memorize) cannot use x=y, y=x; must use a temporary variable t=x; x=y; y=t;
21. if Statement
It is particularly important to note: In C language, non-zero represents logical true, and zero represents logical false. C language has constructed types, but no logical types. if only manages the following single statement; to manage multiple, please use curly braces!
Note the following rules:
1) else matches the closest if statement that has no else.
2) if(a<b)t=a; a=b; b=t; if(a<b){t=a; a=b; b=t;} the difference between the two has been tested multiple times in exams!
3) Standalone if statement: if(a<b)t=a;
Standard if statement: if(a<b)min=a; else min=b;
Nested if statement: if(a<b)
if (b>c) printf(“ok!”);
Multi-choice if statement: if(a==t) printf(“a”);
else if(b==t) printf(“b”); else if(c==t) printf(“c”); else printf(“d”);
Through exercises, become familiar with the above types of if statements!