First, multiple-choice questions (2 points for each question, * * * 20 points)
1. The data type of C language in the following options is ().
A. Complex type B. Logical type C. Set type D. Double precision type
2. The execution of C program comes from ()
A. the main () function starts until the main () function ends. B. The first function starts until the last function ends.
C. Start from the first sentence until the end of the last sentence. The D. Main () function starts until the last function ends.
3, there is a statement int a = 3;; Then execute the statement a+= a-= a * a; After that, the value of variable A is ()
A.3 B.0 C.- 12 D.9
4.If char c [5] = {'c ',' d ',' \ 0 ',' \ 0 ' }; Execute printf statement ("%s", c); The result is ().
A.cd\0e B.'c''d' C.cd D.cd e
5. It is known that: int a [2] [3] = {1, 2,3,4,5,6}, (* p) [3] = a; Then the following expression is not 4 ().
A.*(* p+3)b . * p+3 c . *(*(p+0)+3)d . a[0][3]
6. The following statement about macro replacement is incorrect ().
A. Macro replacement does not take up running time. B. Macro name has no type.
C. Macro replacement is just string replacement. D. Macro names must be expressed in uppercase letters.
7. Execute charstr [10] = "ch \ nina"; The value of strlen(str) is ()
A.5 B.6 C.7 D.9
8. The output of the following program is: ()
# Define power (x) (x*x)
Master ()
{ int I = 4; printf("%d ",POWER(I-2)); }
A.-9 B- 7 c . 5d-6
9. in the definition of int a[3][4][2]; After that, the 10 th element is ()
a . a[2][ 1][2]b . a[ 1][0][ 1]c . a[2][0][ 1]d . a[2][2][ 1]
10, the output of the following program is: ()
Typedef structure
{ long x[2]; & ltbr & gt short y [4]; & ltbr & gtchar z[8]; & ltbr & gt} MYTYPE
My type a;
Master ()
{ printf("%d\n ",sizeof(a)); }
A.2 B. 8 C. 14 D. 24
Two. Fill in the blanks (each blank 1, * * each blank 1 1)
1, and the number of bytes occupied by the string "a" in memory is.
2. Identifiers in C language can only be composed of letters, underscores and.
3. If there is a definition statement "int a=25, b= 14, c =19;" The execution result of the following statement is
if(a++ & lt; = 25 & amp& ampb-& lt; = 2 & amp& ampc++) printf("***a=%d,b=%d,c=%d\n ",a,b,c);
else printf("###a=%d,b=%d,c=%d\n ",a,b,c);
4. It has the following definition: a [] = "b172 \ \' a%%"; Execute printf statement ("%d", strlen(a));); The result is.
5. int A [12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,1,/kloc-0. for(I = 0; I<4; i++)p[I]= & amp; a[I * 3]; Then the value of *(*(p+ 1)+2) is, and the value of *p[2] is. If the first address of the array is 2000, the address that p[ 1] points to is.
6. Let a = 2, b = 3, x = 3.5 and y = 2.5, then the result of the expression (float)(a+b)/2+(int)x%(int)y is.
7. If both X and Y are int variables with an initial value of 1, the expression:-x&; After & y++,the value of y is.
8. The statement is (i =1; I = = 10; I++) continue; The number of cycles is.
9, the following program output.
Master ()
{enum em {em 1=3,em2= 1,em3 };
char *aa[]={"AA "," BB "," CC "," DD " }; printf("%s%s%s\n ",aa[em 1],aa[em2],aa[em3]);
}
Three, write the program results (5 points per question, ***35 points)
1, # contains
Master ()
{int x,y,z; & ltbr & gtx= 1,y=2,z = 3; x+= y+= z; & ltbr & gtprintf(" 1:%d\n ",z+= x & gt; y? x++:y++); & ltbr & gtx = 0x 02 ff; y = 0x ff 00; & ltbr & gtprintf("2:%d\n ",(x & ampy)>; & gt4 | 0x 005 f); & ltbr & gtx = y = z =- 1; ++ x | | ++ y & amp; & amp++ z; & ltbr & gtprintf("3:%d,%d,%d\n ",x,y,z); & ltbr & gt}
2. # Define f(x) x*x
Master ()
{int a=6,b=2,c; & ltbr & gtc = f(a+b)/f(b); & ltbr & gtprintf("%d\n ",c); & ltbr & gt}
3, fun (int k)
{ printf("%d ",k);
if(k & gt; 0)
Fun (k-1);
}
Master ()
{ int w = 5; Fun (w); printf(" \ n "); }
4, # including
Master ()
{int x= 1,y = 0; & ltbr & gt switch (x) < br & gt{ case 1:& lt; Br y)& lt; switch (y) < br & gt{ case 0:printf(" first \ n "); Break; & ltbr & gtcase 1:printf(" second \ n "); Break; & ltbr & gt}
Case 2: printf ("third \ n");
}
}
5, # including
Master ()
{ int k = 4;
func(k); func(k);
}
func(int a)
{Static integer m = 0;;
m+= a;
printf("%d ",m);
}
6. Structure st
{ int x;
int * y;
} * p;
int s[]={30,20 };
struct st a[]={ 1,& amps[0],2,& amps[ 1]};
Master ()
{ p = a; printf("%d ",p-& gt; x);
printf(" % d \ n " ,++((++p)-& gt; y));
}
7. Assume that there are two text files in the current disk directory, and their names and contents are as follows:
File name: a1.txta2.txt.
Content: ABCDEF# abcdef#
# contains "stdio.h"
Master ()
{ FILE * fp& ltbr & gtvoid fc(); & ltbr & gtif((fp=fopen("a 1.txt "," r ")= = NULL)& lt; Br & gt{printf ("Cannot open file! \ n "); Exit (1); }
else { fc(FP); fclose(FP); }
if((fp=fopen("a2.txt "," r ")= = NULL)
{printf ("Cannot open file! \ n "); Exit (1); }
else { fc(FP); fclose(FP); }
}
Empty fc(fp 1)
FILE * FP 1;
{ char c; & ltbr & gtwhile((c=fgetc(fp 1))! = ' # ')putchar(c); & ltbr & gt}
Fill in the blanks (2 points for each blank, *** 14 points)
1, the following procedure finds the sum of the main diagonal elements of matrix A, please fill in the blanks.
Master ()
{ int a[3][3]={2,4,6,8, 10, 12, 14, 16, 18 };
int sum=0,I,j;
for(I = 0; I<3; ① )
for(j = 0; ② ; j++)
if(I = = j)sum = sum+③;
printf("sum=%d\n ",sum);
}
2. The following function coy copies all the characters in the character array S2 to the character array S 1. When copying,' \0' should also be copied, and the characters after' \0' are not used.
coy(char s 1[],char s2[])
{ int I;
for(I = 0; s2[i]! = ① ; i++)
s 1[I]= S2[I];
② ;
}
3. The function of the following program is to sort the odd elements in the string A from small to large, leaving the other elements unchanged. Please fill in the blanks.
Master ()
{char a[]= "student", t; int i,j;
for(I = 1; I<7; i+=2)
for(j = I+2; j & lt8; ① )
If (2)
{ t = a[I]; a[I]= a[j]; a[j]= t; }
Put option (a);
}
C language test questions (2)
1. Fill in the blanks (2 points for each question, ***20 points)
The basic data types of 1.c language are: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _;
Structure types are: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. P. 13
2. The annotation symbol of C language source program is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
In order to show the hierarchical structure, the C language source program is usually written in the format of _ _ _ _ _ _ _ _ _ _ _ _ _. Page 4
3. The compilation target file of the source program test. C is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _;
After connection processing, the generated executable file is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
4. The value of strlen ("1234 \ 0xy) is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _;
The value of sizeof(float) is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
5. The first address of the last line of the two-dimensional array a[ 10] [50] is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _;
The first address of the last element is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
6. In the C standard library function, the prototype of mathematical function is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. P. 130
7. The known function is defined as int stat (int a, float *p).
{……………}
Then the two parameter types of this function are _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
8. Let int x, y, z = 4;;
x = y = ++ z;
x =(y & gt; z)? x+2; x++; Then the value of x is: _ _ _ _ _ _ _;
Let int a = 0, b = 0 and c = 0;; c = ++ a | | b++; , then the values of a, b and c are _ _ _ _ _ _ _ _.
9. The equivalent form of if (x = 0) is written as if (! x);
It is common to judge whether two (floating-point) variables X and Z are equal: if (fabc (x-z).
10. Known assignment statement. Year =1985; It can be judged that Zhang is a _ _ _ _ _ _ _ _ type variable;
The C statement that defines the file pointer is: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
2. Multiple choice questions (each question 1, * * * each question 10)
The basic unit of 1.C program is _ _ _ _ _ _ _ _ _ _ _ _ _ _.
A. Function B. Identifier C. Expression D. Statement
2. If the length of data of type int is 2 bytes, the value range of this type of data is _ _ _ _ _ _ _ _ _ _ _.
A.0 to 65536b
C.-32767 to 32768d. -32768 to 32767
3. In C language, the logical value "true" is represented by _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
A. Macros predefined as true values B. Non-zero numbers
C. positive number D. non-zero integer
4.c language stipulates that else always matches _ _ _ _ _ _ _ _ _ _ for nested if statements.
A. use the outermost if B. use the nearest if before
C. the nearest if D without else. And the nearest if before {}
5. Array definition CHAR A [10] = {` A', ` b', ` c'}: It includes several elements _ _ _ _ _ _ _ _ _ _ _.
A.3 B.9 C.4 D. 10
6. When the array name is passed as a parameter to the called function, the formal parameter gets _ _ _ _ _ _ _ _ _ _ _ _.
A. the value of the first element in array B. The values of all elements in the array.
C. the first address of the first element in the array. The first address of all elements in the array.
7. In order to express the relationship x ≥ y ≥z, the correct expression in C language is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
A.(x & gt= & gty & gt= z)b .(x & gt; =y) and (y & gt=z)
C.(x & gt= y)& amp; & amp(y & gt= z)d .(x & gt; y)& amp; (y & gt=z)
8. According to the definition, int a [] = {1, 2,3}, i, * p = a;; The syntax analysis of _ _ _ _ _ _ _ _ _ is incorrect.
A.a[p-a]b . *(& amp; a)c . p . d . *(*(a+I))
9. If there is a statement scanf ("%d% d ",&; I. & AMPB); Make variables A and B get 12 and 34 respectively; The correct input form is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
A. 12 34 B. 12,34 C. 1234 D. 12:34
10 . union uex int I; Floating f; char c; The value of ex sizeof (ex) is _ _ _ _ _ _ _ _ _ _ _.
a4 b . 5 c . 6d . 7
3. Analyze the program and write the running results. (4 points for each question, ***20 points)
1. The source program is as follows. At runtime, it is assumed that the keyboard input string is "2004".
# Including
Invalid master (invalid)
{
int n = 0;
char c;
while( (c=getchar())! =`\n`) /* Number of characters */
{
if(c & gt; = ` 0` & amp& ampc & lt=`9` )
n = n * 10+c-` 0 `; /* Numbers */
}
printf("value=%d|n ",n);
}
The result is: value =2004.
2. The source program is as follows:
# Including
Invalid master (invalid)
{
int num[9]= { 3993983973963952992903 1 1,30 1 };
int score[9]={8 1,85,59,77,90,66,89,93,73 };
int iMax,iPos,I;
iPos = 0;
iMax = score[iPos];
for(I = 1; I<9; i++)
if(score & gt; iMax)
{
IPos = me;
iMax = score[iPox];
}
Printf ("quantity =%d, score =%d", quantity [ipos]; Score [IPOS]);
The results are: num=3 1 1, score=93.
3. The source program is as follows. Assume that the keyboard input data during operation is: 1 2 3 4 5 6 7 8 9 10.
# Including
Invalid master (invalid)
{
int i,a[ 10];
int * p;
p = a;
for(I = 0; I< 10; i++)
scanf("%d ",p++);
for(p = a; p & ltSPAN & gt; p++)
if (*p%2)printf("%3d ",* p);
}
The result is: 1 3 5 7 9.
4. The source program is as follows, run twice, and input data 13 and 2 1 respectively.
# Including
# Including
Invalid master (invalid)
{
int n,s;
Missing ("%d", & ampn);
S = disc end (n);
if(s = = 1)printf(" yes \ n ");
else printf(" no \ n ");
}
int panduan(int n)
{
int k,j;
k =(int)sqrt((double)n);
for(j = 2; j & lt=k,j++)
{
if(n % j = = 0)break;
}
if(j & gt; k)retum( 1);
else retum(0);
}
The result is affirmative.
no
5. The source program is as follows, assuming that the keyboard input character at runtime is: AxByCz.
# Including
# Including
Invalid master (invalid)
{
String [80];
int I;
gets(str);
for(I = 0; str! =`\0`; i++)
if(str & gt; = `a` & amp& ampstr & lt= ` z `)str-= 32;
else if(str & gt; = `A` & amp& ampstr & lt= ` z `)str+= 32;
Sell (str);
}
The result is: aXbYcZ
4. Every line in the following process has an error. Correct the mistakes in the line to meet the requirements of the topic. (4 points for each corpse, ***20 points)
1. Find s= 1+2+3+,,,+100.
Include corrected to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
Void sum (void) is corrected to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
{
int s,I;
for (s=0,I = 1; I<= 100; i++)
{
s = s+i++; It is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
}
Printf ("s =% f ",s) is corrected to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
}
2. the source program realizes X.
# Including
Dual power (floating. Int) corrected to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
Invalid master (invalid)
{
int i,n;
Floating x;
scanf ("%f,%d ",& ampx & amp; n);
for(I = 1; I<9; i++)
printf("%d,%e\n ",I,pow(i,x);
} corrected to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
Dual v v power supply (floating point x, integer n)
{
int I;
Double p = 0;; It is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
for(I = 1; I< I++) > It is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
p * = x;
retum(p);
}
3. The source programs are arranged in ascending order.
# Including
Invalid master (invalid)
{
int i,j,iMin,a[ 10]={4,3,5, 1, 10, 12,2,6,7,9},iTemp
for(I = 0; I<9; i++)
{
iMin = 0; It is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
for(j = I+ 1; j & lt 10; j++)
if(a[iMin]& lt; iMin = " j;" & gt it is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
If (iMin==i) is revised to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
{ iTemp = a;
a[iMin]= a; It is _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
a[iMin]= iTemp;
}
}
for(I = 0; I< 10; i++)
printf("%4d ",a):
}
4. Average the source program.
# Including
Invalid master (invalid)
{
Int i and sum are exactly _ _ _ _ _ _ _ _ _ _ _ _ _.
Floating average;
int sc[ 10],* p = sc
for (i=0,i & lt 10; I++) is corrected to _ _ _ _ _ _ _ _ _ _ _.
{
scanf("%d ",p++);
sum+= * p; It is _ _ _ _ _ _ _ _ _ _ _ _ _.
}
avg = sum/ 10; Correct it to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
printf("avg=%f ",avg);
}
5. The source program needs eX= 1+x+x2/2! +……+xn/n! The sum of the first n+ 1
# Including
void main(void & gt;
{
float exp,x,t;
int i,n;
scanf("%f,%d ",& ampx & amp; n);
t = 0; Correct it to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
exp = 1.0;
for(I = 1; I < = n; i++)
{
if(t & lt; 1e-6) cycle; Correct it to _ _ _ _ _ _ _ _ _ _ _.
t+= x/I; Correct it to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
exp * = t; Correct it to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
}
printf("\n% 15.6f ",exp);
}
Verb (abbreviation of verb) programming questions (6 points for each question, ***30 points)
1. Write a subfunction to exchange the values of two integer variables X and Y according to the following program framework. ..
# Including
void swap (int *,int *);
Invalid master (invalid)
{
int x,y;
scanf("%d,%d ",& ampx & amp; y);
Interchange (ampx & amp; y);
printf("%d,%d ",x,y);
}
Invalid exchange ()
{
}
2. Set a class of 36 students to take the C language test, and use the one-dimensional array score[36] to store the test results. Some programs are given, and the following programs are improved to realize statistics and output the number and percentage of failures.
# Including
Invalid master (invalid)
{ int I;
Floating scooter [36], percentage;
int count = 0;
for(I = 0; I & lt36; i++)
{
Scanf("%f ",& score);
}
3. Improve the following program, so that it can input a string of characters at will through the keyboard, and calculate the number of uppercase letters ia, lowercase letters iA and other characters iother.
# Including
# Including
Invalid master (invalid)
{
String [80];
int i,iA=0,ia=0,io ther = 0;
}
4. Improve the following program to find the sum of the main and auxiliary diagonal elements of a square matrix and its transposed matrix. Let the square matrix be represented by a two-dimensional array A, the transposed matrix by t, and S 1 and s2 represent the sum of the main and auxiliary diagonal elements.
# Including
Invalid master (invalid)
{
int a[3] [3]={ 1,3,5,7,9, 1 1, 13, 15, 1 1 };
int i,j,s 1,S2;
int t[3][3];
printf("%d,%d,\n ",s 1,S2);
for(I = 0; I<3; i++)
for(j = 0; j & lt3; j++)
printf("%3d ",t[j]);
}
5. Given the character array str[80], write a sub-function that returns a pointer to find the position where the character ch first appears.
# Including
# Including
# Including
char *lstrchar(char*,char);
Invalid master (invalid)
{
char c,*p,str[80];
gets(str);
scanf("%c ",& ampc);
p=lstrchar(str,c);
if(p = = NULL)printf(" char % c not found \ n " c);
Else printf ("position is %d", p-str);
char "lstrchar()
{ }
The real questions and answers of C language in the National Computer Level 2 Examination over the years
/upload files/20064222324839 . rar