01

Given that x, y, and t are all int type variables, after executing the statement: x=y=3; t=++x||++y; the value of y is ( )
A) Undefined value
B) 4
C) 3
D) 2

Answer: C
Explanation:
The short-circuit characteristic of || (logical OR):
If the expression on the left of || is true (non-zero), the expression on the right will not be evaluated, and it directly returns 1 (true). If the left side is false (0), then the right side will be evaluated.
Pre-increment of ++x and ++y:
++x will first increment x by 1, then return the new value of x. ++y works similarly, but in this case, it is not executed.
Pre-increment: increment first, then use
Post-increment: use first, then increment
02

Consider the following code segment:
int k=0;
while(k=1)
k++;
The number of times the while loop executes is ( )
A) Infinite times
B) Syntax error, cannot execute
C) Not executed at all
D) Executed once

Answer: A
Explanation:
k = 1 is an assignment expression that assigns 1 to k. Since k = 1 will always assign 1 to k and return 1 (true), the loop condition will never become false, thus the while loop will execute infinitely.
Note: Distinguish between = and ==
= is the assignment operator
== is the equality operator
03

The C language expression that correctly represents the logical relationship “a >= 10 or a <= 0” is ( )
A) a >= 10 or a <= 0
B) a >= 0 | a <= 10
C) a >= 10 && a <= 0
D) a >= 10 || a <= 0

Answer: D
Explanation:
For option A: ‘or’ is not a valid operator in C language.
For option B: ‘|’ is a bitwise OR (operating on binary bits, not suitable for logical judgment), and the logical relationship is incorrect.
For option C: ‘&&’ is logical AND.
Supplement:
‘&&’ logical AND
‘||’ logical OR
‘!’ logical NOT
‘&’ bitwise AND
‘|’ bitwise OR
‘~’ bitwise NOT
‘^’ bitwise XOR
Order of precedence:
Logical NOT, bitwise NOT, bitwise AND, bitwise XOR, bitwise OR, logical AND, logical OR
04

The C language expression that represents the relationship x ≤ y ≤ z is ( )
A) (x <= y) && (y <= z)
B) (x <= y) AND (y <= z)
C) (x <= y <= z)
D) (x <= y) & (y <= z)

Answer: A
Explanation:
For option A: using logical AND ‘&&’ represents “and”, which conforms to C language syntax.
For option B: ‘AND’ is not a valid operator in C language.
For option C: C language will first evaluate x <= y (resulting in 0 or 1), then compare (result) <= z, which is logically incorrect.
For option D: ‘&’ is bitwise AND, although in some cases the result may be the same as ‘&&’, it does not conform to logical operation norms and is not recommended for use.
05

Let: int a=1, b=2, c=3, d=4, m=3, n=3; after executing (m=a>b)||(n=c>d), the value of n is ( ).
A) 0
B) 1
C) 2
D) 3

Answer: A
Explanation:
The precedence of relational operators is higher than that of assignment operators, and logical OR ‘||’ has the short-circuit characteristic (if the left side is true, the right side is not evaluated), but in this case, the final result of the expression in the left parentheses is false (0), so the right side must be evaluated. Since 3 > 4 results in false (0), n is finally assigned 0.
06

Which of the following statements about the operands of logical operators is correct ( )
A) Can only be integers 0 or 1
B) Can only be integers 0 or non-zero integers
C) Can be data of struct type
D) Can be any valid expression

Answer: D
Explanation:
For option C: In C language, the operands of logical operators must be scalar types. These types can be implicitly converted to 0 (false) or non-zero (true), and thus can be directly used in logical operations.
Structures are not allowed to participate directly in logical operations in C language because they cannot be implicitly converted to 0/1.
Structures are aggregate types, not scalar types. If you need to determine whether a structure is “valid”, you need to manually compare its members.
07

If x and y are both int type variables, x=100, y=200, and the following code segment exists:
printf(“%d”,(x,y));
The output result of the above code segment is ( )
A) 200
B) 100
C) 100 200
D) Output format specifier insufficient, output uncertain value

Answer: A
Explanation:
The characteristic of the comma operator: In C language, the comma operator is used to separate expressions and returns the value of the last expression.
08

During the function call process, if function funA calls function funB, and function funB calls function funA, then ( )
A) It is called direct recursive call of the function
B) It is called indirect recursive call of the function
C) It is called circular call of the function
D) Such recursive calls are not allowed in C language

Answer: B
Explanation:
Function funA calls function funB, and function funB calls function funA, the function indirectly calls itself through another function, which is classified as indirect recursive call.
Supplement:
Classification of function recursive calls
Direct recursion: The function directly calls itself
Indirect recursion: The function indirectly calls itself through another function
C language allows both direct and indirect recursion, as long as there is a termination condition to avoid infinite recursion.
09 (Common Mistake)

The output result of the following program is ( )
main()
{ int k=17;
printf(“%d,%o,%x \n”,k,k,k);
}
A) 17,021,0×11
B) 17,17,17
C) 17,0×11,021
D) 17,21,11

Answer: D
Explanation: The decimal integer 17 converted to octal is 021, and to hexadecimal is 0x11.
However, in this question, %o is used to output octal integers, but does not display the prefix (0); similarly, %x is used to display hexadecimal integers, but does not display the prefix (0x), so the final output of the program is 17,21,11.
Supplement:
%: Format output data
%%: Used to output a single %
%o: Print data in octal format, default without prefix.
%#o: Print data in octal format, display prefix (0)
%x: Print data in hexadecimal format, default without prefix.
%#x: Print data in hexadecimal format, display prefix (0x)
[Variant Question]
The output result of the following program is ( )
main()
{ int k=17;
printf(“%d,%#o,%#x \n”,k,k,k);
}
A) 17,021,0×11
B) 17,17,17
C) 17,0×11,021
D) 17,21,11
Answer: A
10

Let x, y, z be defined as int type variables, if data is input from the keyboard for x, y, z, the correct input statement is ( ).
A) INPUT x, y, z;
B) scanf(“%d%d%d”,&x,&y,&z);
C) scanf(“%d%d%d”,x,y,z);
D) read(“%d%d%d”,&x,&y;&z);

Answer: B
Explanation:
For option A: C language does not have the INPUT keyword.
For option B: Correct, both the format specifier and address passing are correct.
For option C: Incorrect, the address is not passed using &.
For option D: Incorrect.
Supplement: Usage of scanf function
1. Function: Reads data from standard input (such as keyboard) and stores it in variables according to specified format.
2. Core rules:
Format control string: Specifies the type of input data. Variable address list: Must use & address operator (except for string arrays).
3. Commonly used format specifiers
%d Decimal integer
eg: scanf(“%d”, &num)
%f Floating point number (float)
eg: scanf(“%f”, &x)
%lf Double precision floating point number (double)
eg: scanf(“%lf”, &y)
%c Single character
eg: scanf(“%c”, &ch)
%s String
eg: scanf(“%s”, str)
%o Octal integer
eg: scanf(“%o”, &oct)
%x Hexadecimal integer
eg: scanf(“%x”, &hex)
4. Input multiple data
Method 1: Use space/Tab key/newline to separate input
Method 2: Specify delimiter (such as comma)