超星Fundamentals of C Programming_3课后答案(学习通2023完整答案)

高中课后习题2024-05-19 05:34:0097136抢沙发
超星Fundamentals of C Programming_3课后答案(学习通2023完整答案)摘要: Chapter 1 Introducing C-2Quiz 1 Introducing C1、Which of the following is not the standard of C langu ...

超星Fundamentals of C Programming_3课后答案(学习通2023完整答案)

Chapter 1 Introducing C-2

Quiz 1 Introducing C

1、超星Which of the following is 课后not the standard of C language?
A、K&R C
B、答案C89/C90,学习 C99
C、ISO/IEC 9899:2011
D、通完Native C

2、整答When compile a C program,超星 the comments will .
A、be compiled and appear in the object code.
B、课后be compiled,答案 but not appear in the object code.
C、not be compiled and not appear in the object code.
D、学习not be compiled,通完 but appear in the object code

3、A file written by C language .
A、整答can be executed immediately.
B、超星is 课后a source program.
C、can be executed after compilation.
D、答案can be executed after compilation and interpretation.

4、Which of the following languages can be recognized by CPU directly?
A、nature language.
B、advanced language.
C、machine language.
D、assembly language.

5、Many programming languages borrow heavily form C language, including C++, Java, C# and Perl.

6、By writing C compilers for other computers, C program can be run in different platforms.

7、One of C’s advantages is efficiency. Because C was intended for applications where assembly language had traditionally been used, it was crucial that C programs could run quickly and in limited amounts of memory.

8、C’s weaknesses arise from the same source as many of its strengths: C’s closeness to the machine.

Chapter 2 Data Types and Expression -2

Quiz 2 DataType, Variable and Constant

1、Which of the following is a legal C identifier?
A、1stuNPU
B、Stu@NPU
C、stu-NPU
D、_stu_NPU

2、Which of the following is not keyword in C language?
A、do
B、int
C、void
D、main

3、Which of the following program is right?
A、#include <stdio.h> int main(); { /*programming*/ printf("programming!\n"); return 0; }
B、#include <stdio.h> int main() { /*programming*/ printf("programming!\n"); return 0; }
C、include <stdio.h> void main() { /*programming*/ printf("programming!\n") return 0; }
D、#include <stdio.h> int mian() { /*programming*/ printf("programming!\n"); return 0; }

4、Which of the following statement is wrong?
A、Keywords can be used as identifiers in C language.
B、Identifiers in C language must begin with a letter or underscore.
C、C is case-sensitive.
D、C places no limit on the maximum length of an identifier.

5、The extended ASCII character set uses one byte to represent character, therefore the number of characters that the extended ASCII character can represent is .
A、1024
B、256
C、128
D、80

6、Which of the following is not a constant in C language?
A、'AB'
B、012
C、"a"
D、'\n'

7、Which of the following is not a float constant in C language?
A、2.38
B、.23
C、1.2e-2
D、e-2

8、The three identifiers, weight, Weight and WEIGHT, are equal in C language.

Chapter 2 Data Types and Expression -3

Quzi 3 Operators and Expressions

1、In C language, which of the following operator requires its operands must be of type int?
A、/
B、*
C、%
D、=

2、Of which operation the precedence is higher than others’?
A、()
B、%
C、++
D、,

3、Suppose int k=7, x=12; of which expression the value is 3?
A、x%=(k%=5)
B、x%=(k-k%5)
C、x%=k-k%5
D、(x%=k)-(k%=5)

4、The value of the expression 3.6-5/2+1.2+5%2 is ____.
A、4.3
B、4.8
C、3.3
D、3.8

5、Given a statement f = (3.0, 4.0, 5.0), (2.0, 1.0, 0.0); , which of the following conclusion is right?
A、This statement has syntax error.
B、The value of f is 5.0.
C、The value of f is 0.0.
D、The value of f is 2.0.

6、Suppose all variables in the following expressions have been declared and initialized, which of the following is not a legal expression in C language?
A、a := b + 1
B、a = (2, b= c + 2)
C、(int)18.5%3
D、a = b += c + b

7、If an expression is the sum of four data of different types, including int, long, double and char, the expression’s type is ____.
A、int
B、long
C、double
D、char

8、The expressions ++i and i++ are exactly the same as (i += 1).

Chapter 3 program control structure -1

Quiz 4 Formatted Input & Output

1、If c is a variable of type char, which one of the following statements is illegal?
A、i += c; /*i has type int*/
B、c = 2*c – 1;
C、putchar(c);
D、printf(c);

2、Suppose that we call scanf as follows: scanf(“%d%f%d”, &i, &x, &j); If the user enters: 10.8 9 3↙ What will be the values of i, x, and j after the call? (Assume that i and j are int variables and x is a float variable. ↙ is used to represent Enter key)
A、10 0.8 9
B、10 9 3
C、11 9 3
D、10.8 9 3

3、Suppose that we call scanf as follows: scanf(“%f%d%f”, &x, &i, &y); If the user enters: 12.3 45.6 789 What will be the values of x, i, and y after the call? (Assume that x and y are float variables and i is an int variable. ↙ is used to represent Enter key)
A、12.3 45 789
B、12.3 45.6 789
C、12 45 789
D、12.3 45 0.6

4、Which one of the following is correct?
A、The output item must be given when calling function printf.
B、The header file stdio.h must be included before calling function putchar.
C、In C language, integers can be output in various forms, e.g. decimal, binary, octal and hexadecimal.
D、When calling function getchar to read in a character, we can input its corresponding ASCII code.

5、Assuming the following statements: char c1='1',c2='2'; c1=getchar(); c2=getchar(); putchar(c1); putchar(c2); If input a└┘↙ when run the code, ↙ is used to represent Enter key, └┘ is used to represent space, which one of the following statements is correct?
A、Variable c1 is assigned the character a, and c2 is assigned the space character.
B、The program will wait for the second character input by user.
C、Variable c1 is assigned the character a, and c2 remains the character 2.
D、Variable c1 is assigned the character a, and c2 remains uncertain value.

6、Given the following declarations and scanf function call statements, to make the value of a1, a2, c1, c2 to be 10, 20, A and B respectively. Which one of the following inputs is correct? ↙ is used to represent Enter key and └┘ is used to represent space. ( D ) int a1,a2; char c1,c2; scanf("%d%d",&a1,&a2); scanf("%c%c",&c1,&c2);
A、1020AB↙
B、10└┘20↙ AB↙
C、10└┘20└┘AB↙
D、10└┘20AB↙

7、Assuming the statement scanf("a=%d,b=%d,c=%d",&a,&b,&c); To make the values of a, b, and c to be 1, 3, 2 respectively, which of the following input is correct? ↙ is used to represent Enter key and └┘ is used to represent space.
A、132↙
B、1,3,2↙
C、a=1└┘b=3└┘c=2↙
D、a=1,b=3,c=2↙

8、If the variable x is of type double, which one of the following statements is right?
A、scanf("%f",x);
B、scanf("%f",&x);
C、scanf("%lf",&x);
D、scanf("%5.1f",&x);

9、What is the output of the following code? └┘ is used to represent space. float x=-1023.012; printf("%8.3f,",x); printf("%10.3f",x);
A、1023.012,-1023.012
B、–1023.012,-1023.012
C、1023.012,└┘-1023.012
D、–1023.012,└┘-1023.012

10、What is the output of the following code? int x=13,y=5; printf("%d",x%=(y/=2));
A、3
B、2
C、1
D、0

11、If we declared int a=1234;, what is the result when executing the statement printf("%2d",a);?
A、12
B、34
C、1234
D、Error

12、What is the output of the following code? int a; char c=10; float f=100.0; double x; a=f/=c*=(x=6.5); printf("%d %d %3.1f %3.1f",a,c,f,x);
A、1 65 1 6.5
B、1 65 1.5 6.5
C、1 65 1.0 6.5
D、2 65 1.5 6.5

13、Execute the following statements, if input 12345678↙,what is the output? int a , b ; scanf("%2d%*2d%3d",&a,&b); printf("%d",a+b);
A、46
B、579
C、5690
D、Error

14、C compilers are required to check that the number of conversion specifications in a format string matches the number of output items.

15、If the format string is “%d\n”, scanf will skip white space, read an integer, and then skip to the next non-white-space character. So a format string like this can cause an interactive program to “hang” until the user enters a nonblank character.

Chapter 3 program control structure -3

Quiz 5 Selection Structure

1、After the execution of the following statements: int a=1, b=2, c=3, d=4, m=2, n=2, cond; cond = (m=a>b) && (n=c>d); , which one of the following value is equal to the value of n ?
A、1
B、2
C、3
D、4

2、Suppose i is a variable of type int, and its value is 10, which of the following is the value of expression 30-i<=i<=9 ?
A、0
B、1
C、9
D、20

3、After the execution of the following statements: int a=0,b=0,m=0,n=0; (m=a==b)||(n=b==a);,the values of m and n are and respectively?
A、0 0
B、0 1
C、1 0
D、1 1

4、Which of the following is equal to the expression !x ?
A、x==1
B、x==0
C、x!=1
D、x!=0

5、Suppose int x=3,y=4,z=5; , which of the following is the value of the expression !(x+y)+z-1 && y+z/2 ?
A、6
B、2
C、1
D、0

6、Which of the following is not a legal expression in C language?
A、0<=x<100
B、i=j==0
C、(char)(x<100)
D、x+1=x+1

7、The expression in if(expression) can be .
A、logical expression
B、relational expression
C、arithmetic expression
D、any of the above

8、When execute the following program: #include <stdio.h> int main() { int x,y; scanf("%d%d",&x,&y); if (x>y) x=y;y=x; else x++;y++; printf("%d,%d",x,y); return 0; } Which one of the following is correct?
A、Syntax error while compiling
B、If input 3 and 4, it outputs 4 and 5
C、If input 4 and 3, it outputs 3 and 4
D、If input 4 and 3, it outputs 4 and 5

9、In C language, the rule on embedded if statement is that else is always paired with .
A、the previous nearest unpaired if
B、the first if
C、if with the same indent
D、the most front if

10、Which one is correct when execute the following code? int x=0,y=0,z=0; if (x=y+z) printf("***"); else printf("###");
A、Syntax error while compiling
B、It outputs ***
C、Error while linking
D、It outputs ###

11、If a=1, b=3, c=5, d=4,the value of x is when execute the following program. if (a<b) if (c<d) x=1 ; else if (a<c) if (b<d) x=2 ; else x=3 ; else x=6 ; else x=7 ;
A、1
B、2
C、3
D、4

12、Which one of the following is equal to the statement y=(x>0 ? 1: x<0 ? -1:0); .
A、y=0; if (x>=0) if (x>0) y=1; else y=-1;
B、if (x) if (x>0) y=1; else if (x<0) y=-1; else y=0;
C、y=-1; if (x) if (x>0) y=1; else if (x==0) y=0; else y=-1;
D、if (x>0) y=1; else if (x<0) y=-1; else y=0;

13、What is the output of the following program? #include <stdio.h> int main() { int x=1,y=0,a=0,b=0; switch(x) { case 1: switch (y) { case 0 : a++ ; break ; case 1 : b++ ; break ; } case 2: a++; b++; break ; case 3: a++ ; b++ ; } printf("a=%d,b=%d",a,b); return 0; }
A、a=1, b=0
B、a=2, b=1
C、a=1, b=1
D、a=2, b=2

14、If int i=10; the value of i will be after executing the following code. switch (i) { case 9: i+=1 ; case 10: i+=1 ; case 11: i+=1 ; default: i+=1 ; }
A、10
B、11
C、12
D、13

15、Given the declaration: float w; int a, b; , which one of the following is a legal switch statement?
A、switch (w) { case 1.0:printf("*\n"); case 2.0:printf("**\n"); }
B、switch (a); { case 1:printf("*\n"); case 2:printf("**\n"); }
C、switch (b) { case 1:printf("*\n"); default:printf("\n"); case 1+2:printf("**\n"); }
D、switch (a+b); { case 1:printf("*\n"); case 2:printf("**\n"); default:printf("\n"); }

16、If int i=1; the value of i will be after executing the following code. switch (i) { case '1': i+=1 ; case '2': i+=1 ; case '3': i+=1 ; default : i+=1 ; }
A、2
B、3
C、4
D、5

17、After the execution of the following statements: int i=5, j=4, k=6 ; float f; f = (i<j&&j<k)? i : (j<k) ? j : k ; , which one of the following value is equal to the value of f ?
A、4.0
B、5.0
C、6.0
D、7.0

18、After the execution of the following statements: int m1=5,m2=3; m1>m2 ? (m1=1):(m2=-1);, the values of m1 and m2 are respectively?
A、1 and 3
B、1 and -1
C、5 and -1
D、5 and 3

19、switch statements can be totally replaced by if statements at any time.

20、The expression in a case label of a switch statement must be constant expression.

21、The statement if and switch can be embedded.

22、The conditional expression and if statement can be totally replaced by each other.

23、Duplicate case labels aren’t allowed in switch statement.

24、In switch statement, several case can execute the same program segment.

25、The controlling expression in switch statement can be an expression of any type.

26、The case branch in switch statement can be a compound statement or multiply statement sequence.

27、Without break (or some other jump statement) at the end of a case, control will flow into the next case.

Chapter 3 program control structure -4

Quiz 6 Loop Structure

1、What is the output of the following program? #include <stdio.h> int main() { int x=0,y=5,z=3; while(z-->0&&++x<5) y=y-1; printf("%d, %d, %d",x,y,z); return 0; }
A、3, 2, 0
B、3, 2, -1
C、4, 3, -1
D、5, -2, -5

2、Which one of the following contains an infinite loop?
A、for (i=1;;) { if (i++%2==0) continue ; if (i++%3==0) break ; }
B、for (i=1;;) if (++i<10) continue ;
C、i=32767; do { if (i<0) break ; } while (++i) ;
D、i=1 ; while (i--);

3、The following code . x=-1; do{ x=x*x; }while (!x);
A、is an infinite loop
B、loops for 2 times
C、loops for 1 time
D、has syntax error

4、Which one of the following statements is correct?
A、do statement cannot be replaced by the other iteration statements.
B、do statement can only be terminated by break statement.
C、do statement will be terminated when its controlling expression is non-zero.
D、do statement will be terminated when its controlling expression is zero.

5、Assume the following code: int n=0,p; do { scanf("%d",&p); n++; } while (p!=12345 && n<3);When , the loop will terminate.
A、p is not equal to 12345 and n is less than 3
B、p is equal to 12345 and n is not less than 3
C、p is not equal to 12345 or n is less than 3
D、p is equal to 12345 or n is not less than 3

6、Given the following for statement: int i,k; for (i=0,k=-1; k=1 ; i++,k++) printf("***"); Which one of the following conclusions is correct?
A、The above for statement contains illegal expression.
B、The above for statement is an infinite loop.
C、The above for statement loops for 1 time.
D、The above for statement never loops.

7、The loop times of the following for statement are . for (i=2; i==0;) printf("%d",i--);
A、infinite
B、0
C、1
D、2

8、What is the output of the following program? #include <stdio.h> int main() { int i,sum; for(i=1;i<6;i++) sum+=i; printf("%d",sum); return 0; }
A、unpredictable
B、0
C、14
D、15

9、Assume s, a, b, c are declared as integers, and a, c have been assigned values (c>0), s=a; for(b=1; b<=c; b++) s=s+1;Which one of the following is equal to the above code?
A、s=a+b;
B、s=a+c;
C、s=s+c;
D、s=b+c;

10、What is the output of the following program? #include <stdio.h> int main() { int i=0,s=0; for (;;) { if(i==3||i==5) continue; if (i==6) break; i++; s+=i; }; printf("%d",s); return 0; }
A、10
B、13
C、21
D、It contains an infinite loop and will not output anything.

11、If the variables i and p have been declared and initialized correctly, which one of the following cannot calculate 5! ?
A、for(i=1,p=1;i<=5;i++) p*=i;
B、for(i=1;i<=5;i++) { p=1; p*=i; }
C、i=1; p=1; while(i<=5) { p*=i; i++; }
D、i=1; p=1; do{ p*=i; i++; }while(i<=5);

12、In the following programs, which one has the different output with the others’?
A、k=1 while (1) { s+=k ; k=k+1; if (k>100) break ; } printf("%d",s);
B、k=1; Repeat : s+=k ; if (++k<=100) goto Repeat printf("%d",s);
C、int k,s=0; for (k=1;k<=100;s+=++k); printf("%d",s);
D、k=1; do{ s+=k; }while (++k<=100); printf("%d",s);

13、What is the output of the following program? #include <stdio.h> int main() { int k=0,m=0,i,j; for (i=0; i<2; i++) { for (j=0; j<3; j++) k++ ; k-=j ; } m = i+j ; printf("k=%d,m=%d",k,m); return 0; }
A、k=0,m=3
B、k=0,m=5
C、k=1,m=3
D、k=1,m=5

14、Which one of the following is not correct?
A、The statements in C language, except compound statements, must be ended with semicolons.
B、An empty statement does not affect the program in any location.
C、Compound statements are regarded as one single statement in syntax.
D、An assignment statement can be made by adding a semicolon at the end of the assignment expression.

15、Assume the following program fragment: int k=2; while (k=0) { printf("%d",k) ; k-- ; }Which one of the following is correct?
A、while statement loops for 10 times.
B、The loop is infinite.
C、The loop never runs.
D、The loop runs for only one time.

16、while in do statement can be omitted sometimes.

17、Any of the 3 expressions in for loop can be omitted, and so is while and do statement’s controlling expression.

18、The most powerful iteration statement is for statement.

19、The loop body in the for statement will be executed at least once.

20、break can be used in switch statements and loops (while, do, and for), whereas continue is limited to loops.

Chapter 4 The Preprocessor

Quiz 7 Preprocessor

1、Which one of the following statements is wrong?
A、Preprocessing directive must begin with #.
B、A line which begins with # in C program is a preprocessing directive.
C、The preprocessing directives in C program are processed during executing.
D、Preprocessing directives can appear in any line of a C program.

2、Which one of the following statements about macro substitute is wrong ?
A、Macro substitute does not occupy the executing time.
B、Macro name does not have data type.
C、Macro substitution is just string substitution.
D、Macros must be named with capital letters.

3、Assuming we have #define L(x) 2*3.14*x,thus L(x) is .
A、function name
B、function invoking
C、macro with no arguments
D、macro with argument

4、Assuming we have #define P(x) x/x, what is the output after executing printf("%d",P(4+6)); ?
A、1
B、8.5
C、11
D、11.5

5、Assuming the macro definition #define MOD(x,y) x%y, what is the result of the following code? int z,a=15; float b=100; z=MOD(b,a); printf("%d",z++);
A、11
B、10
C、6
D、Syntax error

6、Which one of the following macro for square calculation will not cause ambiguity in any case?
A、#define POWER(x) x*x
B、#define POWER(x) (x)*(x)
C、#define POWER(x) (x*x)
D、#define POWER(x) ((x)*(x))

7、Given a macro definition as follows: #define N 3 #define Y(n) ((N+1)*n), which one of the following is the value of the expression 2*(N+Y(5+1))?
A、error
B、42
C、48
D、54

8、Given a macro definition #define p(x,y,z) x=y*z; the substitution p(a,x+5,y-3.1) will be .
A、a=x+5*y-3.1;
B、a=(x+5)*(y-3.1);
C、a=x+5*y-3.1
D、a=(x+5)*(y-3.1)

9、In the file including preprocessing directives, when the file name is enclosed by double quotes after #include, the file will be searched in .
A、in the standard searching directory of system setting
B、in the source file directory first, then the standard directory searching of system setting
C、only in the source file directory
D、only in the current directory

10、In the file including preprocessing directives, when the file name is enclosed by angle bracket after #include, the file will be searched .
A、in the standard searching directory of system setting
B、in the source file directory first, then the standard directory searching of system setting
C、only in the source file directory
D、only in the current directory

11、Macro substitution does not have type problem, and its arguments are of no type either.

12、In C language standard library header files, many system function prototype are declared. Therefore, as long as these functions are used in the program, these header files should be included, for checking the function calling by compiling system.

13、#include directive can include a C source file with function definition.

14、The header files included by #include must have the suffix .h.

Chapter 5 Array

Quiz 8 Arrays

1、When index the array element, which one of the following statements is wrong?
A、The array subscript can be integer constant.
B、The array subscript can be integer expression.
C、The array subscript can be integer constant or integer expression.
D、The array subscript can be expression of any types.

2、Which one of the following declarations can define a one dimensional array a correctly in C89?
A、int a(10);
B、int n=10,a[n];
C、int n; scanf("%d",&n); int a[n];
D、#define SIZE 10 int a[SIZE];

3、Assume a declaration int a[10]; , which one of the following can reference the element in a correctly?
A、a[10]
B、a[3]
C、a(5)
D、a[-10]

4、Which one of the following statements is wrong?
A、In C, the arrays cannot be assigned values integrally in an assignment statement.
B、Array name represents the starting address of this array in the memory, which cannot be changed.
C、If the index of an array element exceeds the range pre-defined, system will give an error message “array index out of bounds”, while executing.
D、The length of an array can be determined by initializer.

5、Assume the declaration int a[3][4]; which one of the following can index the element in a correctly?
A、a[2][4]
B、a[3][3]
C、a[0][0]
D、a[3][4]

6、Assume the declaration int a[3][4]=; which one of the following statements is correct?
A、Only the element a[0][0] is initialized to 0.
B、It is a wrong statement.
C、Each element in a is initialized but not to 0.
D、Each element in a is initialized to 0.

7、If a 2-D array a has m columns, the formula to index the element a[i][j] is .
A、i*m+j
B、j*m+i
C、i*m+j-1
D、i*m+j+1

8、What is the output of the following code? int k,a[3][3]={ 1,2,3,4,5,6,7,8,9}; for (k=0;k<3;k++) printf("%d",a[k][2-k]);
A、3 5 7
B、3 6 9
C、1 5 9
D、1 4 7

9、Which one of the following initialization is correct for the 2-D array a?
A、int a[3][3]={ };
B、int a[2][2]={ 1,2,3,4,5,6};
C、int a[3][3]={ 1,2,3,4,5,6};
D、int a[2,3]={ 1,2,3,4,5,6};

10、Assume the declaration int b[]={ 1,2,[8]=3,4,5,[15]=1,6,7}; the length of array b is .
A、8
B、17
C、18
D、uncertain

Chapter 6 Functions

Quiz 9 Functions

1、Which one of the following statements about function is right?
A、Every function can be called by the other functions, including main function.
B、Every function can be compiled separately.
C、Every function can be run separately.
D、A function can be defined in the function body of another function.

2、Which one of the following statements is right?
A、Function definitions can be nested, but function calls cannot be nested.
B、Function definitions cannot be nested, but function calls can be nested.
C、Both function definitions and function calls cannot be nested.
D、Both function definitions and function calls can be nested

3、Which one of the following function definitions is right?
A、double f(int x,int y) { z=x+y ; return z ; }
B、double f(int x,y) { double z=x+y ; return z ; }
C、double f(x,y) { int x, y ; double z ; z=x+y; return z ; }
D、double f(int x,int y) { double z ; z = x+y ; return z ; }

4、If call a function int f(), which does not contain any return statement, which one of the following conclusions is right?
A、This function does not return any value.
B、This function returns a system default value.
C、This function returns the value 0.
D、This function returns an unpredictable value.

5、Which one of the following determines the return type of a function in C language?
A、The expression type in the return statement
B、The calling function
C、Compiler
D、The return type specified by function definition

6、Which one of the following statements about function return type is wrong?
A、Function return type can be int.
B、Function return type can be array.
C、Function return type can be char.
D、Function return type can be void.

7、Which one of the following statements is wrong?
A、Actual parameter can be a constant, a variable or an expression.
B、Formal parameter can be a constant, a variable or an expression.
C、Formal parameter can be of any type.
D、The data types of formal parameter and actual parameter can be different.

8、Which one of the following is right?
A、A function call must return a value.
B、Actual parameter and formal parameter can have the same name.
C、The data passed in functions cannot be global variables.
D、The calling function and the called function must be in the same file.

9、Given a function definition as follows: void f(char ch, float x ) { ...... } which one of the following function call statements is right?
A、f("abc",3.0);
B、t=f('D',16.5);
C、f('65',2.8);
D、f(32,32);

10、Assume a program defines a function as follows: double f(double a,double b) { return (a+b); } but the definition is written after calling f. Therefore, f should be declared before the calling. Which one of the following prototypes is wrong?
A、double f(double a,B);
B、double f(double,double);
C、double f(double b,double A);
D、double f(double x,double y);

11、Which one of the following statements about function declaration is wrong?
A、If the definition of a function precede its calls, its function declaration is not required.
B、A function prototype doesn’t have to specify the names of the function’s parameters, as long as their types are present.
C、C99 has adopted the rule that either a declaration or a definition of a function must be present prior to any call of the function.
D、Function prototypes of standard C functions are not required.

12、If an array name is used for an actual parameter in a function calling, which one of the following will be delivered to the corresponding formal parameter?
A、the starting address of the array.
B、the value of the 1st element in the array.
C、all the element values in the array
D、the number of the elements in the array.

13、Given the following code in the main function, which one of the following is an incorrect declaration of the formal argument in function f? int a[3][4]; f(a);
A、f(int array[3][4])
B、f(int array[][4])
C、f(int array[3][])
D、f(int array[4][3])

14、Read the following program: int fun1(double a) { return a*=a;} int fun2(double x,double y) { double a=0,b=0; a=fun1(x); b=fun1(y); return (int)(a+b); } if w is a variable of type double, what is the value of w, after executing the statement w=fun2(1.1,2.0);?
A、5.21
B、5
C、5.0
D、0.0

15、Both function definition and function call can be nested.

16、A function must have a return value, otherwise it cannot be defined as a function.

17、Specifying that the return type is void indicates that the function doesn’t return a value.

Chapter 7 Pointers

Quiz 10 Pointers

1、The pointer of a variable indicates the of the variable.
A、value
B、address
C、name
D、a symbol

2、Given int k=2; int*ptr1,*ptr2; and both ptr1 and ptr2 point to the variable k, which one of the following assignments is not correct?
A、k=*ptr1+*ptr2
B、ptr2=k
C、ptr1=ptr2
D、k=*ptr1*(*ptr2)

3、Given int*p,m=5,n; which one of the following statements is right?
A、p=&n; scanf("%d",&p);
B、p=&n ; scanf("%d",*p);
C、scanf("%d",&n); *p=n ;
D、p=&n; *p=m;

4、Given int*p,a=4; and p=&a; in which one of the following, all items indicate addresses?
A、a,p,*&a
B、&*a,&a,*p
C、*&p,*p,&a
D、&a,&*p,p

5、If a pointer p points to a variable x, which one of the following is equal to *&x ?
A、x
B、p
C、&x
D、&*p

6、If the pointer p points to an integer variable x, which one of the following is equal to (*p)++ ?
A、x++
B、p++
C、*(p++)
D、&x++

7、For two pointer variables of the same base type, which one of the following operations cannot be done?
A、<
B、=
C、+
D、-

8、Given the following function and the variable declaration int a=25; which one of the following is the result of the statement print_value(&a); ? void print_value(int *x) { printf("%d",++*x); }
A、23
B、24
C、25
D、26

9、Given char s[10]; which one of the following is not the address of s[1]?
A、s+1
B、s++
C、&s[0]+1
D、&s[1]

10、Given int a[5],*p=a; which one of the following is a correct reference to an element in array a ?
A、*&a[5]
B、a+2
C、*(p+5)
D、*(a+2)

11、Given int a[5],*p=a; which one of the following is a correct reference to the address of an element in array a ?
A、p+5
B、*a+1
C、&a+1
D、&a[0]

12、Given int x[]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0},*p=x,k; and k is larger than or equal to 0 and less than 10, which one of the following is a wrong reference to the array element x[k]?
A、p+k
B、*(x+k)
C、x[p-x+k]
D、*(&x[k])

13、Given int x[6]={ 2,4,6,8,5,7},*p=x,i; which one of the following code cannot output the 6 elements in array x in order?
A、for(i=0;i<6;i++) printf("%2d",*(p++));
B、for(i=0;i<6;i++) printf("%2d",*(p+i));
C、for(i=0;i<6;i++) printf("%2d",*p++);
D、for(i=0;i<6;i++) printf("%2d",(*p)++);

14、Given int a[2][3]; which one of the following is a correct reference to the address of the element in i-th row and j-th column of array a?
A、*(a[i]+j)
B、(a+i)
C、*(a+j)
D、a[i]+j

15、Given int a=3,b,*p=&a;which one of the following statements doesn’t assign the value 3 to b?
A、b=*&a;
B、b=*p;
C、b=a;
D、b=*a;

16、Given int a[4][5]; which one of the following references is incorrect?
A、*a
B、*(*(a+2)+3)
C、&a[2][3]
D、++a

17、Given int a[2][3],(*p)[3]; p=a; which one of the following references to an element in the array a is correct?
A、(p+1)[0]
B、*(*(p+2)+1)
C、*(p[1]+1)
D、p[1]+2

18、Given int (*p)[4]; which one of the following statements is right?
A、p is a pointer to an integer variable
B、p is a name of the pointer array
C、p is a pointer to a 1D array with 4 integer elements
D、p is declared illegally.

19、The return value of the function char* fun(char *p){ return p; } is .
A、uncertain value
B、the address value in argument p
C、the address of a temporary memory unit
D、the address value of the formal argument

Chapter 8 Strings

Quiz 11 Strings

1、Which one of the following declarations can define a one-dimensional array a correctly?
A、int a[5]={ 0,1,2,3,4,5};
B、char a[]={ 0,1,2,3,4,5};
C、char a={ 'A','B','C'};
D、int a[5]="0123"

2、Assuming char x[]="12345",y[]={ '1','2','3','4','5',''}; which one of the following statements is correct?
A、The lengths of array x and y are equal.
B、x is longer than y.
C、x is shorter than y.
D、Arrays x and y share the same memory area.

3、Which one of the following initializations of the character array s is wrong?
A、char s[5]={ "abc"};
B、char s[5]={ 'a','b','c'};
C、char s[5]="";
D、char s[5]="abcde";

4、Which one of the following character arrays cannot be used as a string?
A、char s[]="happy";
B、char s[6]={ 'h','a','p','p','y',''};
C、char s[]={ "happy"};
D、char s[5]={ 'h','a','p','p','y'};

5、Which is the output of the following code? char c[5]={ 'a','b','','c',''}; printf("%s",c);
A、'a''b'
B、ab
C、ab c
D、abc

6、Given two arrays of character, a and b, which one of the following statements is correct?
A、gets(a,b);
B、scanf("%s%s",a,b);
C、scanf("%s%s",&a,&b);
D、gets("a"); gets("b");

7、Which is the output of the following code? char a[7]="abcdef"; char b[4]="ABC"; strcpy(a,b); printf("%c",a[5]);
A、└┘
B、\0
C、e
D、f

8、Which is the output of the following code? char c[]="\t\b\\\0will\n"; printf("%d",strlen(c));
A、14
B、3
C、9
D、6

9、Which one of the following can be used to test whether the string a is greater than b?
A、if (a>b)
B、if (strcmp(a,b))
C、if (strcmp(b,a)>0)
D、if (strcmp(a,b)>0)

10、The value of the expression strcmp("3.14","3.278") is .
A、non-zero integer
B、float number
C、0
D、character

11、Given the following code: #include <stdio.h> #include <string.h> int main() { char p[]={ 'a','b','c'}, q[10]={ 'a','b','c'}; printf("%d %d", strlen(p), strlen(q)); return 0; } Which one of the following statements is true?
A、When initializing arrays p and q, the system will add the string terminator automatically, so the output lengths are both 3.
B、The value of strlen(p) is uncertain since p doesn’t have the string terminator, but the string length in array q is 3.
C、The value of strlen(q) is uncertain since q doesn’t have the string terminator, but the string length in array p is 3.
D、Neither of the lengths of arrays p and q can be determined since they are without the string terminators.

12、Which is the output of the following code? char w[][10]={ "ABCD","EFGH","IJKL","MNOP"} , k; for(k=1;k<3;k++) printf("%s",w[k]);
A、ABCDFGHKL
B、ABCDEFGIJM
C、EFGJKO
D、EFGHIJKL

13、If the function fun is defined as: void fun(char ch[], float x) { …… }, which one of the following function call statements is correct for function fun?
A、fun("abc",3.0);
B、t=fun('D',16.5);
C、fun('65',2.8);
D、fun(32,32);

14、Which one of the following statements about character array is wrong?
A、Character arrays can store strings.
B、The strings can be input/output integrally.
C、The character arrays can be assigned values integrally in an assignment statement.
D、The strings in the character array cannot be compared by relational operator.

15、Which one of the following is correct?
A、char *a="china"; is equivalent to char *a; *a="china" ;
B、char str[10]={ "china"}; is equivalent to char str[10]; str[]={ "china";}
C、char *s="china"; is equivalent to char *s; s="china" ;
D、char c[4]="abc",d[4]="abc"; is equivalent to char c[4]=d[4]="abc" ;

16、Which one of the following statement(s) is a correct for the string s?
A、char s[6]="ABCDE";
B、char s[5]={ 'A','B','C','D','E'} ;
C、char s[6] ; s="ABCDE";
D、char *s; scanf("%s",s);

17、Given char s[]="china"; char *p ; p=s ; which one of the following is correct?
A、s and p are exactly equivalent.
B、The content of array s and pointer p is the same.
C、*p is equal to s[0].
D、The length of array s and the length of the string pointed by p are the same.

18、Given char a[]="Itismine", *p="Itismine"; which one of the following is incorrect?
A、a+1 is the address of character ‘t’
B、p cannot point to another constant string variable
C、The address in variable p is changeable.
D、The array a occupies 9 bytes.

19、Given char *cc[2]={ "1234","5678"}; which one of the following is correct?
A、The two elements in array cc store the starting addresses of the strings "1234" and "5678" respectively.
B、The two elements in array cc store the starting addresses of two 1D character arrays with 4 characters respectively.
C、cc is a pointer variable which points to a 1D string array with 2 elements.
D、The elements in the array cc are "1234" and "5678" respectively.

20、Assume s1 and s2 are declared correctly, if we want to execute the statement S when string s1 is greater than s2, which one of the following statements is correct?
A、if(s1>s2)S;
B、if(strcmp(s1,s2))S;
C、if(strcmp(s2,s1)>0)S;
D、if(strcmp(s1,s2)>0)S;

21、Given char s1[]="string1",s2[8],*s3,*s4="string2"; which one of the following is incorrect for library function strcpy?
A、strcpy(s1,s4);
B、strcpy(s2,"string1");
C、strcpy(s3,"string1");
D、strcpy(s2,s1);

Chapter 10 Files

Quiz 13 Files

1、Which one of the following is correct about data file and C language?
A、Files consist of ASCII character sequence and C language can only read and write text files.
B、Files consist of binary data sequence and C language can only read and write binary files.
C、Files consist of records sequence and can be categorized into binary files and text files by the storage form of the data.
D、Files consist of data streams and can be categorized into binary files and text files by the storage form of the data.

2、The system standard input file is .
A、keyboard
B、monitor
C、floppy disk
D、hard disk

3、The system standard output file is .
A、keyboard
B、monitor
C、floppy disk
D、hard disk

4、Which one of the following is a correct file name argument for the function fopen?
A、c:\user\text.txt
B、c:\\user\\text.txt
C、"c:\user\text.txt"
D、"c:\\user\\text.txt"

5、Given char fname[]="infile.dat"; , which one of the following is a correct way to open the text file infile.dat for reading?
A、fopen(infile,"r")
B、fopen("infile","r")
C、fopen(fname,"r")
D、fopen("fname","r")

6、Which one of the following is a correct way to create a file for both reading and writing using the function fopen ?
A、"ab+"
B、"wb+"
C、"rb+"
D、"ab"

7、If errors occur while executing the function fopen, what is its return value?
A、the address
B、NULL
C、1
D、EOF

8、If open an existing file using the argument "a+", which one of the following is correct?
A、When it is open, the origin file content remains, the accessing pointer moves to the end of the file and appending/reading operations are available.
B、When it is open, the origin file content remains, the accessing pointer moves to the beginning of the file and rewriting/reading operations are available.
C、When it is open, the origin file content is deleted, only reading operation is available.
D、None of the above is correct.

9、In the file open modes, the string "rb" indicates .
A、opening an existing binary file only for data reading.
B、opening a text file only for data writing.
C、opening an existing text file only for data reading.
D、opening a binary file only for data writing.

10、When opening the text file "a:\\aa.dat" in the mode "w", if the file already exists, .
A、the new data will be appended to the end of the file.
B、the file will be clear and the new data is written from the beginning.
C、the error message will be displayed.
D、the new data will be insert into the beginning of the file.

11、In C program, which one of the following can write an integer data into a file in binary form?
A、fprint
B、fputs
C、fwrite
D、fputc

12、Which one is the prototype of the function fputc that write a character to the disk files?
A、FILE* fputc(char)
B、int fputc(FILE *)
C、int fputc(char,FILE *)
D、int fputc(FILE *,char)

13、Which one of the following operations can be done using the function fseek?
A、changing the file position associated with the file pointer.
B、sequential file access
C、random file access
D、all of the above

14、The function calling fseek(fp,-20L,SEEK_END) complete the operation .
A、moving the file pointer to the location 20 bytes to the file header.
B、moving the file pointer 20 bytes forward from the current location.
C、moving the file pointer 20 bytes backward from the end of the file.
D、moving the file pointer 20 bytes backward from the current location.

15、Which one of the following codes is nearly equal to fseek(fp,0L,SEEK_SET)?
A、feof(fp)
B、ftell(fp)
C、fgetc(fp)
D、rewind(fp)

16、The function rewind can .
A、move the file pointer to the beginning of the file.
B、move the file pointer to the specific location of the file.
C、move the file pointer to the end of the file.
D、move the file pointer to the location of the next character.

17、The function ftell(fp) can .
A、get the current location of the stream file.
B、move the pointer of the stream file.
C、initialize the pointer of the stream file.
D、all the above.

Chapter 9 Structures

Quiz 12 Structures, Union and Enumerations

1、Given a structure definition as follows: struct stu { int a; float b; } stutype; , which one of the following statements is wrong?
A、struct is a keyword which is used to declare a structure tag
B、struct stu is a user-defined structure type
C、stutype is a user-defined structure type name
D、a and b are structure members

2、For which one of the following definitions, the compiler will not allocate memory locations.
A、struct { char name[10] ; int age ; } student ;
B、struct STUDENT { char name[10] ; int age ; } student ;
C、struct STUDENT { char name[10] ; int age ; } ; struct STUDENT student;
D、struct STUDENT { char name[10] ; int age ; } ;

3、Which one of the following definitions of the structure variable td1 is wrong?
A、#define AA struct aa AA { int n; float m; } td1;
B、struct { int n; float m; } td1;
C、typedef struct aa { int n; float m; } AA; AA td1;
D、struct { int n; float m; } aa; stuct aa td1;

4、When declare a structure variable, the size of space allocated by system is .
A、the sum of the space size required by each member in the structure variable
B、the size of space required by the first member in the structure variable
C、the memory size of the member which requires the largest space in the
D、the size of memory required by the last member in the structure variable

5、Given the declaration of a structure tag named student as follows: struct student { int no ; char name[20]; char sex; struct { int year; int month ; int day ; } birth; } s; if the member birth of the structure variable s is October 1, 2016. Which one of the following assignments is right?
A、year=2016; month=10; day=1;
B、birth.year=2016; birth.month=10; birth.day=1;
C、s.year=2016; s.month=10; s.day=1;
D、s.birth.year=2016; s.birth.month=10; s.birth.day=1;

6、Given the following code, which one of the following statements can output the letter M. struct person { char name[9]; int age; }; struct person class[10]={ "Johu",17,"Paul",19,"Mary",18,"Adam",16};
A、printf("%c",class[3].name);
B、printf("%c",class[2].name[0]);
C、printf("%c",class[3].name[1]);
D、printf("%c",class[2].name[1]);

7、Which one of the following reference to a member of structure is not right? struct pupil { char name[20]; int age; int sex; } pup[5], *p=pup;
A、scanf("%s",pup[0].name);
B、scanf("%d",&pup[0].age);
C、scanf("%d",&(p->sex));
D、scanf("%d",p->age);

8、Which one of the following reference is not right? struct s { int i1; struct s *i2,*i0; }; static struct s a[3]={ 2,&a[1],0,4,&a[2],&a[0],6,0,&a[1]}, *ptr=a;
A、ptr->i1++
B、*ptr->i2
C、++ptr->i0
D、*ptr->i1

9、Given the following declaration: struct sk { int a; float b; } data; int *p; which one of the following assignments is right, to make p point to a in data?
A、p=&a;
B、p=data.a;
C、p=&data.a;
D、*p=data.a;

10、Given the declaration: struct{ int a; char b;} Q,*p=&Q; which one of the following expression is wrong?
A、*p.b
B、(*p).b
C、Q.a
D、p->a

11、Given the following code: struct st { int x; int *y; } *pt; int a[]={ 1,2},b[]={ 3,4}; struct st c[2]={ 10,a,20,b}; pt=c; which one of the following expressions has the value of 11?
A、*pt->y
B、pt->x
C、++pt->x
D、(pt++)->x

12、Which one of the following statements about union is right?
A、A union type cannot contain a member of array.
B、A union variable can store all its members at the same time.
C、A union variable cannot store all its members at the same time.
D、A union type cannot contain a member of type structure.

13、When declare a union variable, the size of space allocated by the compiler is .
A、the sum of the space size required by each member in the union variable
B、the size of space required by the first member in the union variable
C、the memory size of the member which requires the largest space in the union variable
D、the size of memory required by the last member in the union variable

14、Given the following program: union { char a[10]; short b[4][5]; long c[5]; } u; the value of sizeof(u) is .
A、10
B、20
C、40
D、70

15、Given the following program: union data { char ch; int x; } a; which one of the following is not right?
A、a={ 'x',10}
B、a.x=10;a.x++;
C、a.ch='x';a.ch++;
D、a.x=10;a.ch='x';

16、Given the following declaration: enum color { red,yellow=2,blue,white,black} r=white; what is the output after executing the statement printf("%d",r); ?
A、0
B、1
C、3
D、4

17、Given the following declaration: enum week { sun, mon, tue, wed, thu, fri, sat} day; which one of the following assignments is right?
A、sun=0;
B、sun=day;
C、mon=sun+1;
D、day=sun;

18、Which one of the following statements is wrong?
A、All elements in union variable have the same beginning address.
B、A union type can be used to declare array and pointers.
C、A member in a union type can be of type structure, but not of type union.
D、If use typedef to give an old type a new identifier, after that, the old type is still valid.

19、Given the following statement: typedef struct { int n;char ch[8];} PER; which one of the following statements is right?
A、PER is a structure variable name
B、PER is a structure type name
C、typedef struct is a structure type
D、struct is a structure tag

Final Examination

Final Examination

1、Which of the following is a legal C identifier?
A、1stuNPU
B、Stu@NPU
C、stu-NPU
D、stu_NPU

2、In C language, which of the following operator requires its operands must be of type int?
A、/
B、*
C、%
D、=

3、Suppose that we call scanf as follows: scanf(“%f%d%f”, &x, &i, &y); If the user enters: 12.3 45.6 789 What will be the values of x, i, and y after the call? (Assume that x and y are float variables and i is an int variable.)
A、12.3 45 789
B、12.3 45.6 789
C、12 45 789
D、12.3 45 0.6

4、Suppose int x=3,y=4,z=5; , which of the following is the value of the expression !(x+y)+z-1 && y+z/2 ?
A、6
B、2
C、1
D、0

5、The following code . x=-1; do{ x=x*x; }while (!x);
A、is an infinite loop
B、loops for 2 times
C、loops for 1 time
D、has syntax error

6、The three identifiers, weight, Weight and WEIGHT, are equal in C language.

7、The expression in a case label of a switch statement must be constant expression.

8、In switch statement, several case can execute the same program segment.

9、Without break (or some other jump statement) at the end of a case, control will flow into the next case.

10、The loop body in the for statement will be executed at least once.

文章版权及转载声明

本文地址:http://www.zzxhsh.org/41b799940.html发布于 2024-05-19 05:34:00
文章转载或复制请以超链接形式并注明出处五煦查题

评论列表 (暂无评论,44人围观)参与讨论