0% found this document useful (0 votes)
13 views28 pages

100 Questions

The document contains a series of quiz questions related to the C programming language, covering topics such as data types, operators, control statements, and syntax rules. Each question presents multiple-choice answers, testing knowledge on various aspects of programming in C. The quizzes are structured into chapters, with each chapter focusing on different programming concepts.

Uploaded by

raimovamirbek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views28 pages

100 Questions

The document contains a series of quiz questions related to the C programming language, covering topics such as data types, operators, control statements, and syntax rules. Each question presents multiple-choice answers, testing knowledge on various aspects of programming in C. The quizzes are structured into chapters, with each chapter focusing on different programming concepts.

Uploaded by

raimovamirbek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Review

Chapter 1 Quiz (8)


1.
Computer software is commonly classified into two kinds, application software
and system software. The most important system software is .
A.Language process system
B.Operating system
C.Security
software
D.Database management system

2.Which one of the following is a legal C identifier?


A.stu-NPU
B._stu_NPU
C.1stuNPU
D.Stu@NPU

3.Which of the following is not keyword in C language?


A.do
B.void
C.main
D.int

4.The binary equivalent of 127 in decimal is .

A.11111110
B.01111111
C.11111111
D.10000000

5.Which one of the following languages can be recognized by CPU directly ?

A.assembly language
B.nature language
C.machine language
D.advanced language

A file written by C language .


A.can be executed immediately.
B.is a source program.
C.can be executed after compilation and interpretation.
D.can be executed after compilation.

7.A computer system contains two parts, software and .hardware

8.The function is mandatory in C program.main

Chapter 2 Quiz (Part I) (7)


9
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.)

A.10.8 9 3
B.10 9 3
C.11 9 3
D.10 0.8 9

10
In C language, which one of the following operators requires its operands must
be of type int?
A.=
B./
C.%
D.*

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

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

13
Suppose all variables in the following expressions have been declared and
initialized, which of the following is a legal expression in C language?
A.a := b + 1
B.18.5%3
C.a = a + 7 = c + b
D.a = b = c + 2

14

Which of the following statement is wrong?


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

15
What output does the following call of printfproduce?

printf(“%6d, %.4f”, 86, 83.162);


Chapter 2 Quiz (Part II) (11)
16

Which one of the following is not a legal type in C language?


A.long short
B.signed short int
C.unsigned int
D.unsigned long int

17

If c is a variable of type char, which one of the following statements is illegal?


A.i+= c; /*i has type int*/
B.putchar(c);
C.c = 2*c – 1;
D.printf(c);

18

Which one of the following is not a constant in C language?


A.'\n'
B.e-2
C."a"
D.012

19

If an expression contains data of four different types, including int, long,


unsigned and char, the expression’s type is .
A.long
B.unsigned
C.int
D.char
20

In the following variable declarations and initializations, which one is legal?


A.float 2_and=1-e-3;
B.long do=0xfdaL;
C.short _a=1-.1e-1;
D.double b=1+5e2.5;

21

Which one of the following is not a legal way to write the number 65? (Assume
that the character set is ASCII.)
A.0101
B.0b1000001
C.‘A’
D.0x41

22

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 values is equal to the value of n ?
A.4
B.2
C.1
D.3

23

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.1
B.0
C.20
D.9

24

Which one of the following is equal to the expression !x ?


A.x==1
B.x!=1
C.x!=0
D.x==0

25

Which one 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

26

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 values is equal to the value of f ?
A.7.0
B.6.0
C.5.0
D.4.0

27
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.5 and 3
B.1 and 3
C.5 and -1
D.1 and -1

Chapter 3 Quiz (Part I) (11)


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

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

30
Which one is correct when execute the following code?
int x=0,y=0,z=0;
if (x=y+z) printf("***");
else printf("###");
A.Error while linking
B.It outputs ###
C.It outputs ***
D.Syntax error while compiling
31
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 4 and 3, it outputs 3 and 4
C.If input 4 and 3, it outputs 4 and 5
D.If input 3 and 4, it outputs 4 and 5

32.
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.4
D.3
33
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.
y=-1;
if (x)
if (x>0) y=1;
else if (x==0) y=0;
else y=-1;
C.
if (x>0) y=1;
else if (x<0) y=-1;
else y=0;
D.
if (x)
if (x>0) y=1;
else if (x<0) y=-1;
else y=0;

34
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.12
B.11
C.13
D.10
35
C statements can be categorized into controlling statements (selection, loop, jump),
function calling statements, , empty statements and compound statements
(5 types).

36
Compound statements are statement blocks enclosed by a pair of .

37
C language does not provide input/output statement, its input/output operation is
implemented by .

38
Generally, at the beginning of a program file there should be preprocessing
directive , when calling standard formatted input/output library function.

39
When execute a switch block, the statement can make the control quit from
the switch block immediately.

Chapter 3 Quiz (Part II) (16)


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

41
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, which one of the
following is correct?
A.Variable c1 is assigned the character a, and c2 remains the character 2.
B.The program will wait for the second character input by user.
C.Variable c1 is assigned the character a, and c2 remains uncertain value.
D.Variable c1 is assigned the character a, and c2 is assigned a new-line character.

42
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 the
correct? ↙is used to represent Enter key.
int a1,a2;
char c1,c2;
scanf("%d%d",&a1,&a2);
scanf("%c%c",&c1,&c2);
A.1020AB↙
B.10 20AB↙
C.10 20 AB↙
D.10 20↙

AB↙

43
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↙
44
If the variable x is of type double, which one of the following statements is right?
A.scanf("%f",&x);
B.scanf("%lf",&x);
C.scanf("%f",x);
D.scanf("%5.1f",&x);

45
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

46
int x=13,y=5;
printf("%d",x%=(y/=2));
A.0
B.3
C.1
D.2

47
What is the output of the following code?
int x='f';
printf("%c",'A'+(x-'a'+1));
A.H
B.I
C.J
D.G
48
If we declared int a=1234;, what is the result when executing the statement
printf("%2d",a);?
A.1234
B.12
C.34
D.Error

49
Given the declarations: int a=7, b=8; what is the result when execute printf("%d, %d",
(a+b,a), (b,a+b));?
A.15, 7
B.7, 15
C.8, 15
D.Error

50
What is the result when execute printf("a\bre\'hi\'y\\\bou");?
A.abre'hi'y\bou
B.a\bre\'hi\'y\\\bou
C.re'hi'you
D.abre'hi'ybou

51
What is the output of the following code?
int x=102,y=012;
printf("%2d,%2d",x,y);
A.102,12
B.10,01
C.102,10
D.02,12

52
What is the output of the following statements?
int m=0256,n=256;
printf("%o %o",m,n);
A.400 400
B.0256 0400
C.0256 256
D.256 400

53
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.2 65 1.5 6.5
C.1 65 1.0 6.5
D.1 65 1.5 6.5

54
What is the output of the following code?
char a='1',b='2';
printf("%c, ",b++);
printf("%d",b-a);
A.3, 2
B.50, 2
C.2, 50
D.2, 2

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

Chapter 4 Quiz (13)

56
The while statement in the following code loops for times.
int i=0;
while (i<10) {
if (i<1) continue;
if (i==5) break;
i++;
}
A.1
B.6
C.infinite
D.10

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

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

59
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 equal to 12345 and n is not less than 3.
B.p is not equal to 12345 and n is less than 3.
C.p is equal to 12345 or n is not less than 3.
D.p is not equal to 12345 or n is less than 3.

60
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 never loops.
C.The above for statement is an infinite loop.
D.The above for statement loops for 1 time.

61
The loop times of the following for statement are .
for (i=2; i==0; ) printf("%d",i--);
A.2
B.0
C.1
D.Infinite
62
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.15
B.unpredictable
C.0
D.14

63
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=s+c;
C.s=a+c;
D.s=b+c;

64
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.21
B.10
C.The program contains an infinite loop, it will not output anything.
D.13

65
If the variables i and p have been declared and initialized correctly, which one of the
following cannot calculate 5! ?
A.
i=1;
p=1;
do{
p*=i;
i++;
}while(i<=5);
B.
for(i=1,p=1;i<=5;i++){
p*=i;
}
C.
i=1;
p=1;
while(i<=5)
{p*=i;
i++;
}
D.
for(i=1;i<=5;i++)
{ p=1;
p*=i;
}
66
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=1,m=3
B.k=1,m=5
C.k=0,m=5
D.k=0,m=3

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

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

Chapter 5 Quiz - Function (11)

69
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(int x,int y)
{ double z ;
z = x+y ;
return z ;
}
D.
double f(x,y)
{ int x, y ;
double z ;
z=x+y;
return z ;
}
70
Assume a function definition as follows:
fun(int a,float b) {
return a+b;
}
, which one of the following is the return type of this function in C89?
A.int
B.unpredictable
C.void
D.float

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

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

73
Given a function definition as follows:
void f(char ch, float x ) { ...... }
, which one of the following function call statements is right?
A.f(32,32);
B.t=f('D',16.5);
C.f('65',2.8);
D.f("abc",3.0);
74
Assume a program defines a function as follows:
double f(double a,double b)
{ return (a+b); }
, the definition is placed 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 b,double A);
C.double f(double x,double y);
D.double f(double,double);

75
Assume all variables in the following choices have been declared correctly and the
function fun uses a return statement to return a value, which one of the following is
wrong?
A.
int main()
{…… x=fun(2,10); ……}
float fun(int a,int b){……}
B.
float fun(int,int);
int main()
{…… x=fun(2,10); ……}
float fun(int a,int b){……}
C.
int main()
{float fun(int i,int j);
…… x=fun(i,j); ……}
float fun(int a,int b){……}
D.
float fun(int a,int b){……}
int main()
{…… x=fun(i,j); ……}

76
Which one is the output of the following program?
#include <stdio.h>
void F(int x) { return (3*x*x); }
int main(){
printf("%d",F(3+5));
return 0;
}
A.192
B.Compiling Error
C.29
D.25

77
Which one is the output of the following program?
#include <stdio.h>
void fun(int x, int y, int z)
{ z=x*x+y*y; }
int main()
{
int a=31;
fun(5,2,a);
printf("%d",a);
return 0;
}
A.unpredictable
B.0
C.29
D.31

78
Assume a function definition as follows:
int data() {
float x=9.9;
return(x);
}
, when call this function, it will return _____.

79
If a function directly or indirectly calls itself, this function is a function.

Chapter 6 Quiz I - Program organization (1)


80
If a global variable and a local variable have the same identifier in a source file, which one
of the following statements is right?
A.They are regarded as the same variable.
B.It is allowed in C.
C.The scopes of these two variables are uncertain.
D.It is not allowed in C.

Chapter 6 Quiz II - Preprocessing(2)


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

82
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.Syntax error
B.11
C.6
D.10
Chapter 7 Quiz I - Array (13)
83
Assume a declaration int a[10]; , which one of the following can reference the element in
a correctly?
A.a(5)
B.a[-10]
C.a[10]
D.a[3]

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

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

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

87
Assume the declaration intb[][3]={1,2,3,4,5,6,7}; the length of the first dimension of array
b is .
A.2
B.uncertain
C.4
D.3

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

89
Assume the declaration int a[][4]={0,0}; which one of the following statements is wrong?
A.Only the elements a[0][0] and a[0][1] are initialized to 0, while the others are not.
B.The array has 1 row, because the quotient is 0 when divide the number of initial values
by the second dimension size of array a.
C.The length of the first dimension of the 2-D array a is 1.
D.Each element in a is initialized to 0.

90
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 6 9
B.1 5 9
C.1 4 7
D.3 5 7

91
.In C language, the array index starts from , and it cannot be negative.
92
Assuming the definition: int a[3][4]={{1,2},{0},{4,6,8,10}}; the value of a[1][2]
is after the initialization.

Chapter 7 Quiz II - String (3)


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

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

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

Chapter 8 Quiz I - Pointer (4)


96
The pointer of a variable indicates the of the variable.
A.value
B.address
C.name
D.a symbol
97
Given intk=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.k=*ptr1+*ptr2
D.ptr1=ptr2

98
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;

99
Assume p1 and p2 are pointers to the same string; c is a character variable, which one of
the following assignment statements is incorrect?
A.c=*p1*(*p2);
B.p2=c;
C.c=*p1+*p2;
D.p1=p2;

Chapter 8 Quiz II

100. Given char a[]="shanxixian",*p=a; int i; the value of i is , after

executing the statement for(i=0;*p!='\0'; p++,i++);

You might also like