Tải bản đầy đủ (.doc) (116 trang)

BÀI THI TRẮC NGHIỆM LẠP TRÌNH C TRÊN LINUX

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (510.56 KB, 116 trang )

BÀI THI TRẮC NGHIỆM LẬP TRÌNH C TRÊN LINUX
ĐỀ SỐ: 501

1. What value is stored in x after the following two statements are
executed:
int x;
x = 2 / 4 * 4 / 2;
0
B
0.0625
C
1
D
1.0
2. Which of the following statements will correctly output the quote:
Dan Quayle once said, "Who’s responsible for the riots? The rioters."
A
cout << "Dan Quayle once said, "Who\’s responsible for the riots? The
rioters. " ";
B
cout << "Dan Quayle once said, Who’s responsible for the riots? The
rioters.";
C
cout << "Dan Quayle once said, "Who’s responsible for the riots? The
rioters. " ";
D
cout << "Dan Quayle once said, \"Who’s responsible for the riots? The
rioters. \" ";
3. Which of the following will output "Yes" if the integer variable num is
either 2, 3, 4, or 5?
B


C
D
4. Which snippet of code correctly adds the odd integers between 1 and 20?
A
B
C
D
5.
A
B
C
D
6. Which of the following is an invalid comment?
A
// Comment regarding the program
B
/* Comment regarding the program */
C
/**************************
D
/************************** * Comment about the program
**************************/
7. What data types can be used to store numeric values with a decimal
point, such as 3.14 ?
A
short, int
B
long
C
float, double

D
char
8.
A
x = 1, y = 2
B
x = 1, y = 1
C
x = 0, y = 2
D
x = 0, y = 1
9. What value is stored in variable x?
int x;
x = 2 * 3 + 4 * 5 -4 / 2;
A
24
B
11
C
14
D
28
10. How can we input a value from the keyboard and store it in the
variable named num?
A
cout << num;
B
cin >> num;
C
cin << num;

D
num = input();
11. To access functions such as abs, rand, or exit, what should be added to
the top of the program?
A
#include < cmath>
using namespace std;
B
#include < stdlib.h>
C
#include < cstdlib>
using namespace std;
D
#include < iostream>
using namespace std;
12. Which of the following functions correctly returns the minimum of
three integers passed in?
A
B
C
D
13.
3 2 2 3
3 2 1 1
3 2 1 2
3 2 1 3
14.
X =1 Y = 1
B
X =1 Y = 2

C
X =2 Y = 1
D
X =2 Y = 2
15. Which of the following function prototypes is equivalent to the
following prototype?
int min(int num1, int num2, int num3);
A
int min(long num1, long num2, long num3);
B
int min(int, int, int);
C
int min(double num1, double num2, double num3);
D
long min(int, int, int);
16.
A
Before foo, X=1 In foo, X=1, After foo, X=1
B
Before foo, X=1 In foo, X=2, After foo, X=2
C
Before foo, X=2 In foo, X=2, After foo, X=2
D
Before foo, X=1 In foo, X=2, After foo, X=1
17.
A
10 4 10 4
B
10 4 10 3
C

2 3 10 4
D
10 4 2 3
18.
A
10 4 10 4
B
2 3 10 4
C
10 4 10 3
D
10 4 2 3
19.
A
X=3 Y=2
B
X=3 Y=3
C
X=2 Y=3
D
X=2 Y=2
20. Given the following function prototype:
void foo(int arr[]);
Which statement correctly passes the array to the function?
int arr[10]; foo(arr);
B
int arr[10]; foo(arr[]);
C
int arr[10]; foo(arr[0]);
D

int arr[10]; foo(arr[10]);
21. Which of the following correctly declares an array that holds exactly
10 integers?
A
int[10] arr;
B
int[11] arr;
C
int arr[11];
D
int arr[10];
22.
3 2 1
B
1 2 1
C
3 1 1
D
An error message
23. Which of the following is an invalid function prototype to accept a two-
dimensional array of type double?
A
double foo(double arr[10][10]);
B
double foo(double arr[][10]);
C
double foo(double arr[10][100]);
D
double foo(double arr[][]);
24.

A
1 2 3 4 5
B
5 4 3 2 1
C
5 2 3 4 1
D
5 2 3 4 5
25.
3 1 1
B
3 2 1
C
1 2 3
D
1 2 1
26.
A
int main(){
Foo f;
f->printMessage();
return 0;
}
B
int main(){
Foo f;
f::printMessage();
return 0;
}
C

int main() {
Foo f;
f.printMessage();
return 0;
}
D
int main(){
Foo f;
printMessage();
return 0;
}
27. What is the error in the following definition?
class BankAccount{
public:
int ID;
double amount;
}
A
There are no methods
B
There are no private variables
C
There is a missing semicolon after the right curly brace.
D
There are no public accessor methods.
28. Given the following declaration, how do we access the x and y
members of the structure?
struct Point {
int x;
int y;

};
A
Point p;
p->x = 10;
p->y = 20;
B
Point p;
p::x = 10;
p::y = 20;
C
Point p;
p.x = 10;
p.y = 20;
D
Point p;
p:x = 10;
p:y = 20;
29. What is the error in the following definition?
struct BankAccount{
int ID;
double amount;
}
"ID" cannot be all uppercase
B
The keyword "struct" should be "structure"
C
Different data types are not allowed in the struct.
D
There is a semicolon missing after the right curly brace
30. Under the principle of information hiding, which class definition best

encapsulated the variable named "x"?
A
B
C
D
31.
Money m1(10,50), m2(10,50);
A
B
C
D
32.

×