Tạo Trắc Nghiệm

700+ câu trắc nghiệm Ngôn ngữ lập trình C có đáp án - Phần 19

25 câu · Đề ôn tập tổng hợp

Xem trước: đọc nhanh mọi câu dạng chữ, chưa tính giờ, chưa hiện đáp án.
Luyện tập: chọn đáp án là biết đúng sai ngay, kèm lời giải.
Thi thử: nộp bài mới chấm điểm và hiện lời giải.

Câu 1

What is the output of the following code? #include using namespace std; int main() { int a = 20, b = 100; int &n = a; n = a++; n = &b; cout << a << "," << n << endl; system("pause"); }

Đáp án và lời giải

Đáp án: D

Câu 2

What is the output of the following code? #include using namespace std; int main() { int main; main = 100; cout << main++ << endl; system("pause"); }

Đáp án và lời giải

Đáp án: A

Câu 3

The design of classes in a way that hides the details of implementation from the user is known as:

Đáp án và lời giải

Đáp án: D

Câu 4

Which of the following keywords do you think can be used when declaring static members in a class?
(i) Public
(ii) Private
(iii) Protected

Đáp án và lời giải

Đáp án: A

Câu 5

I want a nonmember function to have access to the private members of a class. The class must declare that function:

Đáp án và lời giải

Đáp án: A

Câu 6

The ability to reuse objects already defined, perhaps for a different purpose, with modification appropriate to the new purpose, is referred to as

Đáp án và lời giải

Đáp án: B

Câu 7

What do you think is the outcome of calling a redefined non-virtual function using a base-class pointer?

Đáp án và lời giải

Đáp án: B

Câu 8

A class member that is to be shared among all objects of a class is called

Đáp án và lời giải

Đáp án: C

Câu 9

What is a base class?

Đáp án và lời giải

Đáp án: D

Câu 10

A variable that is declared protected:

Đáp án và lời giải

Đáp án: D

Câu 11

What is a destructor?

Đáp án và lời giải

Đáp án: B

Câu 12

In protected inheritance:

Đáp án và lời giải

Đáp án: B

Câu 13

If a class declares a variable static, this means:

Đáp án và lời giải

Đáp án: B

Câu 14

In case of a copy constructor, which of the following is true?

Đáp án và lời giải

Đáp án: D

Câu 15

A class declaring another class as a friend will:

Đáp án và lời giải

Đáp án: C

Câu 16

Which of the following can be virtual?

Đáp án và lời giải

Đáp án: B

Câu 17

Where is an exception generated?

Đáp án và lời giải

Đáp án: B

Câu 18

Static member functions ___

Đáp án và lời giải

Đáp án: C

Câu 19

mmmmmmmmmm

Đáp án và lời giải

Đáp án: C

Câu 20

In the following program, how many times Base’s constructor will be called? #include using namespace std; class Base { int static i; public: Base() { cout << "Base's constructor"; }; }; class Sub1 : public virtual Base {}; class Sub2 : public Base {}; class Multi : public Sub1, public Sub2 {}; void main() { Multi m; system("pause"); }

Đáp án và lời giải

Đáp án: B

Câu 21

In the following code what would be the values of i1 and i2

#include <iostream>

using namespace std; namespace N1 { int f(int n) { return n * 2; } } namespace N2 { int f(double n) { return n * 3; } } void main() { using N1::f; int i1 = f(1.0); cout << "i1 = " << i1; using N2::f; int i2 = f(1.0); cout << "i1 = " << i2; system("pause"); }

Đáp án và lời giải

Đáp án: B

Câu 22

In the following code, which of the following variables can be accessed in “Friend”? class Base { public: int a; protected: int b; private: int c; }; class Derived : Base { int d; friend Friend; }; class Friend { Derived derived; };

Đáp án và lời giải

Đáp án: D

Câu 23

What is the output of the following code? #include int count = 0; class obj { public: obj() { count++; } ~obj() { count--; } }; int main() { obj A, B, C, D, E; obj F; { obj G; } std::cout << count; return 0; }

Đáp án và lời giải

Đáp án: C

Câu 24

What is wrong in the following code? #include class Base { public: Base() {}; virtual ~Base() {}; }; class Derived : protected Base { public: virtual ~Derived() {}; }; int main() { Base *pb = new Derived(); return 0; }

Đáp án và lời giải

Đáp án: B

Câu 25

What is the output of the following code? #include using namespace std; class professor { public: professor() { cout << "professor "; }; }; class researcher { public: researcher() { cout << "researcher "; }; }; class teacher : public professor { public: teacher() { cout << "teacher "; }; }; class myprofessor : public teacher, public virtual researcher { public: myprofessor() { cout << "myprofessor "; }; }; int main() { myprofessor obj; system("pause"); return 0; }

Đáp án và lời giải

Đáp án: B