Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language final exam questions (Tan Haoqiang version)
C language final exam questions (Tan Haoqiang version)
C language final exam questions

Saturday, April 2008 12, 00:22

Multiple choice questions (24 points, 2 points for each small question)

1. It is known that the calling form of the function fread is fread(buffer, size, count, fp), where buffer stands for ().

A storage area for storing the read data items.

Read the address where the data is stored or a pointer to the address.

File pointer to read file.

An integer variable representing the total number of data items to be read in.

2. The output of the following program is ().

Master ()

{

int i=0 10,j = 10;

printf("%d,%d\n ",i++,j-);

}

a 1 1.9

B 9, 10

8, 10

D 9,9

3. Let a be an int variable, and after the following assignment statements are executed, the values of a are () respectively.

a = 125.534;

a = 20.0/3;

a =(int) 125.52 1% 4;

a = 5 & lt& lt2;

6,3 1, 1

B 125

C 125,6.666666,3 1.20

D 125.534

4. If I and k are both int types, the statement for loop ().

for(i=0,k =- 1; k = 1; i++,k++)

printf(" * * * * \ n ");

The condition for ending loop A is illegal.

B loop body is not executed once.

C loop body is only executed once.

D is an infinite loop.

5. The output of the following program is ().

Master ()

{

char c;

int I;

for(I = 65; I & lt68; i++)

{

c = I+32;

Switch (c)

{

Case "a":

Case "b":

case 'c':printf("%c,",c); Break;

Default value: printf ("end");

}

}

}

A a b c over

End, end

C a,a,a,

D a,b,c,

6. Function call statement: fseek(fp,-10L, 2); It means ().

Move the file location pointer from the end of the file to the beginning of the file 10 bytes.

B. Move the file position pointer from the current position to the file header by 10 bytes.

Move the file location pointer from the current location by 10 bytes to the end of the file.

Move the file location pointer to 10 bytes away from the file header.

7. The output of the following program is ().

Master ()

{

int i=0,j = 0;

while(s 1[i]! ='\0')

i++;

while(s2[j]! ='\0')

s 1[i++]= S2[j++];

s 1[I]= 0;

printf("%s\n ",s 1);

}

one side

B country

Side test

village

8. The following statement is incorrect ().

The variables defined in the main function main are valid in the whole file or program.

Variables with the same name can be used in different functions.

Formal parameters are local variables.

D Within a function, variables can be defined in a compound statement, and these variables are only valid in this compound statement.

9. In the following program segment, the value of enumeration variable c 1 is ().

Enumeration colors (red, yellow, blue =4, green, white) c1;

C 1 = yellow;

C 1 = white;

1

B 3

C 5

D 6

10. There is a description int(* ptr)(); (); Where the identifier ptr is ().

Is a pointer to an integer variable.

B is a pointer to a function whose function value is int.

C is a function name.

The definition of d is illegal.

1 1. defines an array p, which consists of n pointers to plastic data. The correct way is ().

An int p;;

b int(* p)[n];

c int * p[n];

d int(* p)();

12. Pointer type variable p and array a have the same type. The operation that cannot be performed is ().

A p = a

b * p = a[0];

C p = & ampa[0];

D p = & ampa;

Second, to judge whether it is right or wrong, mark "√" for the right and "×" for the wrong (20 points, 2 points for each small question).

1. The data involved in the bit operation can be any type of data. ( )

2. If there is a definition and statement:

int a;

char c;

Floating f;

Scanf("%d, %c, %f ",& i, & c, & f);

If you use the keyboard to input: 10 A 12 5.

Then a = 10, c =' a', f = 12.5. ( )

3. The C language regards a file as a series of characters (bytes). ( )

4. If there is a macro definition:

# define S(a, b) t = a; a = b; b=t

Because the variable t is undefined, this macro definition is wrong. ( )

5. In Turbo C, the following definitions and statements are legal:

file * fp

fp=fopen("a.txt "," r "); ( )

6. If defined:

Char s[ ]= "China";

Turbo C system opens a 6-byte storage unit for array s ... ()

7. If there is a definition and statement:

int a[3][3]={{3,5},{8,9},{ 12,35}},I,sum = 0;

for(I = 0; I<3; i++)

sum+= a[I][2-I];

Then sum=2 1. ( )

8. If there is a definition and statement:

Structural students

{

int num

Character name [10];

Floating score;

}

S[5]={{ 1, "Lili", 98.5}, {9, "Xiaohua", 66}}, * p = s;; printf("%d ",* p++);

The output result is 1. ( )

9. After defining a structural type in the program, you can use it many times to define the variables of that type. ( )

10. In Turbo C, this definition and statement are legal:

enum aa{ a=5,b,c } bb

bb =(enum aa)5; ( )

Write the running results of the following programs (36 points, 6 points for each small question)

1.

Master ()

{

int i=29,j=6,k=2,s;

s = I+I/j % k-9; //s=i+(i/j)%k-9

printf("s=%d\n ",s);

}

2.

Master ()

{

int x=3 1,y=2,s = 0;

do

{

s-= x * y;

x+= 2; y-= 3;

}

while(x % 3 = = 0); //Execute first, then judge.

printf("x=%d\ty=%d\ts=%d\n ",x,y,s);

}

3.

Master ()

{

int a[6]={ 10,20,30,40,50,60},I;

invert(a,0,5);

for(I = 0; I<6; i++)

printf("%d ",a[I]);

printf(" \ n ");

}

Invert (int s [], int i, int j)// inversion

{

int t;

If (I<j)

{

invert(s,i+ 1,j- 1); //Nested calls of the function itself form a loop.

t = s[I];

s[I]= s[j];

s[j]= t;

}

}

4.

# include & ltstdio.h & gt

Master ()

{

Char str[]= "C program", c;

int I;

for(I = 2; (c=str[i])! ='\0'; i++)

{

Switch (c)

{

Case' g':++I; Break; //Because of ++i, 1 letters after G were skipped.

Case "o": Continue;

Default value: printf("%c ",c); Continue;

}

printf(" * ");

}

printf(" \ n ");

}

5.

Structure w// structure

{

Low char;

Char is high;

};

Union u//* * *

{

Structure w bytes;

Short words;

} uw

Master ()

{

Int result;

uw . word = 0x 1234;

printf("word value:%04x\n ",uw . word);

Printf ("high byte: %02x\n", uw.byte.high);

Printf ("low byte: %02x\n", uw.byte.low);

uw . byte . low = 0x 74;

printf("word value:%04x\n ",uw . word);

result = uw . word+0x2a 34;

Printf ("Result: %04x\n", result);

}

6.

Master ()

{

Char *s2= "I love China!" ,* * s 1 = & amp; S2;

char *s3,c,* s4 = " w

s3 = & ampc;

* s3 = ' H

S2 = S2+2;

printf("%s\t%c\t%s\t%c\n ",s2,*s3,s4,* * s 1);

}

Read the following procedure and fill in the appropriate contents to make the procedure complete (20 points, 2 points for each blank).

1 .100 horses bear 100 loads: there are 100 horses, 1 100 loads, 3 loads for big horses, 2 loads for middle horses and 0/load for small horses. How many horses are there?

Master ()

{

int hb,hm,hl,n = 0;

for(HB = 0; hb & lt= 100; hb+=( 1))

for(hm = 0; hm & lt= 100-HB; hm+=(2))

{

HL = 100-h B-(3);

if(hb/3+hm/2+2*(3)== 100)

{

n++;

printf("hb=%d,hm=%d,hl=%d\n ",hb/3,hm/2,2 * HL);

}

}

printf("n=%d\n ",n);

}

2. Sort the input 10 characters by "bubble method" and output them in the order from small to large.

# Definition number 10

char str[N];

void main()

{

int i,flag

for(flag = 1; flag = = 1; )

{

scanf("%s ",str);

flag = 0;

printf(" \ n ");

}

sort(_ _ _(4)_);

for(I = 0; I & ltn;; i++)

{

printf("%c ",str[I]);

}

printf(" \ n ");

}

Sort(charstr[n])// bubble sort

{

int i,j;

char t;

for(j = 1; j & ltn; j++)

for(I = 0; I<10-j; i++)

if(str[i]>str[i+ 1])

{

t = str[I];

____(5)____;

____(6)____; //exchange position

}

}

3. The following program is a function, whose function is to find the sum of the values of all external elements of the second-order matrix (M-row and N-column matrix). (In this program, the second-order matrix is represented by one-dimensional array. )

For example, the matrix is:

3 0 0 3

2 5 7 3

1 0 4 2

Then the sum of the values of all external elements is 3+0+0+3+2+3+1+0+4+2 =18.

add(int m,int n,int arr[])

{

for(I = 0; I & ltm;; i=i+m- 1)

for(j = 0; j & ltn; j++)

sum = sum+_ _ _ _(7)_ _ _ _ _;

for(j = 0; j & ltn; j=j+n- 1)

for(I = 1; ____(8)____; i++)

sum = sum+arr[I * n+j];

Returns (the sum);

}

4. Using pointer as function parameter, programming to find the maximum and minimum element values in one-dimensional array.

# Definition number 10

Master ()

{

void maxmin(int arr[],int *pt 1,int *pt2,int n);

int array[N]={ 10,7, 19,29,4,0,7,35,- 16,2 1},*p 1,*p2,a,b;

p 1 = & amp; a;

p2 = & ampb;

Maxmin (array, p 1, p2, n);

printf("max=%d,min=%d ",a,b);

}

void maxmin(int arr[],int *pt 1,int *pt2,int n)

{

int I;

* pt 1 = * pt2 = arr[0];

for(I = 1; I & ltn;; i++)

{

if(arr[I]& gt; *pt 1)

____(9)____ ;

if(arr[I]& lt; *pt2)

____( 10)____ ;

}

}

answer

Multiple choice questions (24 points, 2 points for each small question)

1.(B ) 2。 (C ) 3。 (2)

4.(D ) 5。 (D ) 6。 (1)

7.(D ) 8。 (1) 9. (4)

10.(B ) 1 1。 (C ) 12。 (4)

Second, to judge whether it is right or wrong, mark "√" for the right and "×" for the wrong (20 points, 2 points for each small question).

1.( × ) 2.( √ )

3.( √ ) 4.( × )

5.( × ) 6.( √ )

7.( √ ) 8.( × )

9.( √ ) 10.( √ )

Write the running results of the following programs (36 points, 6 points for each small question)

1.s=20

2.x=35 y=-4 s=-29

3.60,50,40,30,20, 10,

4.e C pr * am

5. Word value: 1234

6. Love China! Gao w l

High byte: 12

Low byte: 34

Word value: 1274

The result is: 3ca8.

Read the following procedure and fill in the appropriate contents to make the procedure complete (20 points, 2 points for each blank).

1.( 1) 3 (2) 2 (3)hm hl

2.(4)str(5)str[I]= str[I+ 1](6)str[I+ 1]= t

3.(7)arr[I * n+j](8)I & lt; m- 1

4.(9)* ptr 1 = arr[I]( 10)* ptr 2 = arr[I]