01

Read the following program:
main()
{ int a=1, b=3, c=5;
int *p1=&a, *p2=&b, *p3=&c;
*p3=*p1*(*p2);
printf(“%d\n”,c);
}
The output result after execution is
A) 1
B) 2
C) 3
D) 4

Answer: C
Analysis: Brief
02

To write a good program, it is essential to ensure its correctness and reliability, and also to emphasize good programming style. When choosing identifier names, one should consider
A) The shorter the name, the better, to reduce the input size of the source program
B) Multiple variables sharing one name, to reduce the number of variable names
C) Choosing meaningful names to correctly indicate the entities they represent
D) Using keywords as names as much as possible to standardize names

Answer: C
Analysis:
For option A: Incorrect, while short names can reduce input size, excessive abbreviation can lead to decreased code readability, making it difficult to understand and maintain.
For option B: Incorrect, different variables should use independent names; otherwise, it can lead to logical confusion and errors.
For option C: Correct, clear naming can improve code readability and maintainability, which is a core principle of good programming style.
For option D: Incorrect, programming language keywords have special purposes and cannot be used as variable or function names, otherwise it will lead to syntax errors.
03

Read the following program:
#include<stdio.h>
main()
{ int a;
float b, c;
scanf(“%2d%3f%4f”,&a,&b,&c);
printf(“\na=%d, b=%f, c=%f\n”, a, b, c);
}
If the input from the keyboard during runtime is 9876543210<CR>
(<CR> represents carriage return), then the output result of the program is
A) a=98, b=765, c=4321
B) a=10, b=432, c=8765
C) a=98, b=765.000000, c=4321.000000
D) a=98, b=765.0, c=4321.0

Answer: C
Analysis:
Matching input data with format specifiers:
a takes the first 2 digits 98 (integer)
b takes the next 3 digits 765
c takes the next 4 digits 4321
%2d: reads 2-digit integer and assigns it to a
%3f: reads 3-digit float and assigns it to b
%4f: reads 4-digit float and assigns it to c
04

Read the following program:
#include<stdio.h>
f(char *s)
{ char *p=s;
while( *p!=’\0′) p++;
return(p-s);
}
main()
{ printf(“%d\n”,f(“ABCDEF”));}
The final output result of the program is ( )
A) 3
B) 6
C) 8
D) 0

Answer: B
Analysis:
The function f calculates the length of the string (until it encounters the character ‘0’).
The logic of function f:
Initialize pointer p to point to the beginning of the string (p = s);
Move pointer p to the end of the string (i.e., the position of character ‘0’) through while(*p != ‘0’) p++;
Return p – s, which is the length of the string (excluding ‘0’);
05 (Common Mistake)

Read the following program:
#include <stdio.h>
main()
{ int x=1, y=2, z=3;
if (x>y)
if (y<z)
printf(“%d”, ++z);
else
printf(“%d”, ++y);
printf(“%d\n”, x++);
}
The program’s running result is
A) 331
B) 41
C) 2
D) 1

Answer: D
Analysis:
Rules of if-else in C language:
Rule 1: If there is only one statement after if or else, the curly braces {} can be omitted.
Rule 2: else always pairs with the nearest unmatched if (regardless of indentation)
After the first if, there is indeed only one statement – this “statement” is a complete if-else structure. In C language, the if-else as a whole is treated as a single compound statement, so no additional curly braces are needed.
06

Assuming variables x and y are both correctly defined and assigned values. The following if statement will generateerror messages at compile time:
A) if (x++)
B) if (x>y && y!=0)
C) if (x>0) x–
else y++;
D) if (y<0) {;}
else x++;

Answer: C
Analysis:
For option C: Syntax error, missing semicolon or curly braces between if and else, leading to an incomplete structure.
07 (Common Mistake)

Read the following program:
main()
{ int p[7]={11,13,14,15,16,17,18},i=0,k=0;
while(i<7&&p[i]%2)
{k+=p[i]; i++;}
printf(“%d\n”,k);
}
The output after execution is
A) 58
B) 104
C) 45
D) 24

Answer: D
Analysis:
Initial state: i = 0, k = 0.
First loop:
p[0] = 11 (odd), k = 0 + 11 = 11, i = 1.
Second loop:
p[1] = 13 (odd), k = 11 + 13 = 24, i = 2.
Third loop:
p[2] = 14 (even), the loop condition p[i] % 2 becomes false, ending the loop.
[Variant Question]
Read the following program:
main()
{
int p[7]=
{11,13,14,15,16,17,18};
int i=0,k=0;
while(i<7||p[i]%2)
{k+=p[i]; i++;}
printf(“%d\n”,k);
}
The output after execution is
A) 58
B) 104
C) 45
D) 24
Answer: B
08

The following description of operator precedence iscorrect:
A) Relational operators < arithmetic operators < assignment operators < logical AND operators
B) Logical AND operators < relational operators < arithmetic operators < assignment operators
C) Assignment operators < logical AND operators < relational operators < arithmetic operators
D) Arithmetic operators < relational operators < assignment operators < logical AND operators

Answer: C
Analysis: Brief
09

The suffix of C language source program is
A) .exe
B) .c
C) .obj
D) .cp

Answer: B
Analysis:
.c: This is the standard suffix for C language source programs.
.exe: This is the executable file suffix under Windows system, generated by the compiler, not the suffix of the source program.
.obj: This is the suffix for intermediate object files generated after compilation, not the suffix of the source program.
.cp: This is not the standard suffix for C language, it may be the source file suffix for other languages.
10

In C language, if the following variables are all of type int, the output result is
sum=a=5;
a=(sum++,a++,++a);
printf(“%d\n”,a);
A) 7
B) 6
C) 5
D) 4

Answer: A
Analysis: Brief