C Language Exam Practice

multiple choice

1. Which of the following statements is correct ()
A) The source program in C language can be run directly without compiling.
B) Every executable statement in the C language will eventually be converted into binary machine instructions.
C) The binary code formed by compiling the C language source program can be run directly.
D) Functions in C language cannot be compiled separately.

Analysis
A: The C language needs to be compiled and linked before it can run
B: Correct
C: Every C statement will be converted into binary machine instructions after compilation (Compile). After the C language source program is compiled by the C language compiler, a suffix is ​​generated. OBJ binary files, and finally by the software called "linker", this. The OBJ file is connected with various library functions provided by the C language to generate an executable file.
D: Functions in C language can be compiled separately and compiled into object files. When linking into executable files, main functions and libraries are required.

2. In a C language source program ( )
A) There must be one main function B) There may be multiple main functions
C) There must be other functions except the main function D) There is no main function

Analysis:
 A c language program has and can only have one main function, and it must have a main function to complete the connection to an exe file. There can be no other functions, but the executable cannot be built without the main function

3. The following cannot be defined as user identifiers ( )
A) scanf B) Void C) _3com D) int

Parsing
 ①User identifiers are composed of letters, underscores, and numbers, but the beginning must be letters or underscores;
 ②User identifiers cannot use keywords reserved by the system method;
 ③User identifiers are case-sensitive and can be used as variable name.
 Choose option D

4. If the variables in the following options have been correctly defined, the correct assignment statement is ( )
A) x1=26.8%3;  
B) 1+2=x2;  
C) x3=0x12;  
D) x4=1+2= 3;

Analysis:
A The remainder can only be an integer remainder
B The constant cannot be used as an lvalue
D 3 Cannot be assigned to 1+2
Select c item

5. There is a definition: float a=2, b=4, h=3; the following C language expression does not match the calculation result of the algebraic formula ( )

A)(a+b)*h/2  
B)(1/2)*(a+b)*h  
C)(a+b)*h*1/2  
D)h/2*(a+b)

Analysis:
Floating point divided by integer, the result is floating point;
integer divided by integer, the remainder is taken down, the result is integer;
1/2 result is 0; so the result chooses option B

6. The three basic structures used in structured programming in C language are ( )
A) sequence structure, selection structure, loop structure
B) if, switch, break
C) for, while, do-while
D) if, for 、continue

A, do not explain;

7. The !x in the while (!x) statement is equivalent to the following conditional expression ( )

A) x!=0      B) x==1
C) x!=1      D) x==0

 In C language, whether it is true or false is judged by whether it is zero; the number that is not zero is true;
x=2, while is not executed, so you cannot choose C item
 while (x) means while (x != 0) , that is, loop when x is not 0
 , so while (!x) means while (x == 0), that is, loop when x is 0. Choose
D

8. There are the following procedures:

#include <stdio.h>
void main(){
     
     
	int i=1,j=1,k=2;
	if( (j++||k++)&&i++ )
	printf(%d,%d,%d\n”,i,j,k);
}

The output after execution is ( )
A) 1,1,2 B) 2,2,1  
C) 2,2,2 D) 2,2,3

C || operation, judge from left to right, if the left side is true, do not judge the right side, so execute j++, not k++;
&& operation, execute on both sides; therefore execute i++;
get 2 2 2;

9. There are the following procedures:

#include <stdio.h>
void main(){
     
      
int i,s=0;
for(i=1;i<10;i+=2) 
s+=i+1;
printf(%d\n”,s);}

The output after program execution is ( )
A) The sum of the natural numbers 1 to 9 B) The sum of the natural numbers 1 to 10 C) The sum of the
odd numbers in the natural numbers 1 to 9 D) The sum of the even numbers in the natural numbers 1 to 10

Analysis:
i is initially 1, but the value of i+1 is added to s later, which is 2;
i is 3 in the second cycle, and s+ is the value of 3+1, which is 4; and
so on ,
item D is correct ;

10. There is the following function definition:
void fun(int n,double x){……}
If the variables in the following options have been correctly defined and assigned, the correct calling statement for the function fun is ( )
A) fun(int y ,double m);  
B) k=fun(10,12.5);
C) fun(x,n);
D) void fun(n,x);

Choose C
A: You don’t need to write the parameter type when calling
B: The return value type of this function is void (void), there is no return value, so naturally you can’t assign a value to k
D: You don’t need to write the return value type when calling the function

fill in the blank

11. The expression in C language to describe "both x and y are greater than or equal to z" is ()
 x>=z&&y>=z

12. The basic elements involved in the function definition are: _____, ______, _______.
 function name, formal parameters, function body

13. The structured statements that can be used to implement loops in C language are: _____, ______, _______.
 for, while, do-while

14. The C language expression for judging that the integer variable a is an integer multiple of 5 and 7 is: ____________.

(a%5==0)&&(a%7==0)

15. If both x and n are int variables, and the initial values ​​of x and n are both 6, then after calculating the expression x+=n++, the value of x is (), and the value of n is ().
 12 7

write result

16. Procedure 1

#include <stdio.h>
void main() {
     
     
	int a=12,b=12;
	printf(%d,%d\n”,--a,++b); 
}

The output after program execution is _______
 - -a: subtract 1 from the value first, ++b means add 1 to the value first, and then output
Answer: 11,13

17. Procedure 2

#include <stdio.h>
void main() {
     
     
int a=5,b=4,c=3,d=2;
	if(a>b>c) 
		printf(%d\n”,d);
	else if((c-1>=d)==1)
		printf(%d\n”,d+1);
	else
		printf(%d\n”,d+2);
}

The output of the program after execution is: _______

 2
The first branch: a>b is established, return result 1; 1>c is not established; enter the second judgment The second judgment
: c-1 is 2, 2>=d is true; output d+1;
end

18. Procedure 3

#include <stdio.h>
void main() 
{
     
     
	int x=0,y=5,z=3;
	while(z-->0&&++x<5)
		y=y-1;
	printf(%d,%d,%d\n”,x,y,z);
}

The output of the program after execution is _______


Before the cycle starts: x=0 y=5 z=3
After the first cycle: x=1 y=4 z=2
After the second cycle: x=2 y=3 z=1
After the third cycle: x =3 y=2 z=0
The fourth loop judgment does not enter the loop body: x=3 y=2 z=-1

programming questions

19. Write a program. Realize the input of a lowercase letter, and the program outputs its corresponding uppercase letter. (Hint: The ASCII code value of lowercase letters is 32 greater than that of larger letters)

#include<stdio.h>
int main(){
     
     
	char ch;
	scanf("%c",&ch);
	printf("%c\n",ch);
	return 0;
}

Guess you like

Origin blog.csdn.net/Stanford_sun/article/details/123653550