50 CÂU HỎI
What is the output of the following code?
A. 21,21
B. 20,21
C. 21,22
D. compile error
What is the output of the following code?
A. 100
B. 101
C. none
D. compile error
The design of classes in a way that hides the details of implementation from the user is known as:
A. Encapsulation
B. Information Hiding
C. Data abstraction
D. All of the above
Which of the following keywords do you think can be used when declaring static members in a class?
(i) Public
(ii) Private
(iii) Protected
A. all of above
B. (i)
C. (i), (iii)
I want a nonmember function to have access to the private members of a class. The class must declare that function:
A. friend
B. inline
C. static
D. virtual
The ability to reuse objects already defined, perhaps for a different purpose, with modification appropriate to the new purpose, is referred to as
A. Information hiding
B. Inheritance
C. Redefinition
D. Overloading
What do you think is the outcome of calling a redefined non-virtual function using a base-class pointer?
A. The appropriate redefined version of the function will be used
B. The base-class version of the function will always be used
C. The outcome is unpredictable
D. A run-time error will occur
A class member that is to be shared among all objects of a class is called
A. A const member
B. A reference parameter
C. A static member
D. A function member
What is a base class?
A. An abstract class that is at the top of the inheritance hierarchy.
B. A class with a pure virtual function in it.
C. A class that inherits from another class
D. A class that is inherited by another class, and thus is included in that class.
A variable that is declared protected:
A. Is visible only in the subclasses (and not in the class it is declared in)
B. Is visible only in the class it is declared in
C. Is visible to all classes, but modifiable only in the class where it is declared
D. Is visible in the class it is declared in, and all of its sub-classes
What is a destructor?
A. A function called when an instance of a class is initialized
B. A function that is called when an instance of a class is deleted
C. A special function to change the value of dynamically allocated memory
D. A function that is called in order to change the value of a variable
In protected inheritance:
A. The public members of the base class become public
B. The public members of the base class become protected
C. The protected members of the base class become private
D. The public members of the base class become inaccessible
If a class declares a variable static, this means:
A. Each instance of a class will have its own copy of the variable
B. Changing the variable in one instance will have no effect on other instances of the class
C. Changing the variable in one instance will have no effect on other instances of the class
D. Every instance of the class must consider the value of the static variable before initializing
In case of a copy constructor, which of the following is true?
A. Used to instantiate an object from another existing object
B. To copy one object to another existing object
C. Can be a substitute for a ‘=’ operator
D. All of the above
A class declaring another class as a friend will:
A. Have wine and cheese with that other friend
B. Allow that class to declare an instance of it in its list of private variables
C. Allow the other class (the one declared as friend) to access to the declaring class’s private variables
D. Allow the class declaring the other as a friend to access the declared class’s private variables
Which of the following can be virtual?
A. constructors
B. destructors
C. static functions
D. None of the above
Where is an exception generated?
A. In the catch block
B. In the throw clause
C. In the constructor of a class
D. Only when memory allocation fails
Static member functions ___
A. can be used without an instantiation of an object
B. can only access static data
C. Both 1 and 2 are correct
D. Neither 1 nor 2 are correct
What makes a class abstract?
A. The class must not have method
B. The class must have a constructor that takes no arguments
C. The class must have a function definition equal to zero
D. The class may only exist during the planning phase
In the following program, how many times Base’s constructor will be called?
A. 1
B. 2
C. 3
D. error
In the following code what would be the values of i1 and i2
A. i1=2 i2=2
B. i1=2 i2=3
C. i1=3 i2=2
D. Error
In the following code, which of the following variables can be accessed in “Friend”?
A. only a and b
B. a,b and c
C. only a
D. error
What is the output of the following code?
A. 0
B. 5
C. 6
D. 7
What is wrong in the following code?
A. There is nothing wrong
B. One cannot have a ‘Base’ pointer to ‘Derived’ since it is not derived publicly
C. One need a derived class pointer to point to a derived class
D. One required to code a constructor for Derived
What is the output of the following code?
A. professor researcher teacher myprofessor
B. researcher professor teacher myprofessor
C. myprofessor teacher researcher professor
D. myprofessor researcher professor teacher
What is the output of the following code?
A. Parent Parent
B. Parent Child Child Parent
C. Child Parent Parent Child
D. Error
What is wrong in the following code?
A. There is no error
B. There is a syntax error in the declaration of “Method”
C. Class D2 does not have access to “Method”
D. Class D1 must define “Method”
Quy tắc đặt tên biến nào sau đây là đúng?
A. Là một chuỗi gồm một hoặc nhiều ký tự chữ, số hoặc ký tự gạch dưới, bắt đầu bằng một ký tự hoặc dấu gạch dưới.
B. Không chứa các ký hiệu Đểc biệt hoặc dấu cách.
C. Không trùng với các từ khoá.
D. Tất cả các quy tắc đầu đúng.
Kích thước của dữ liệu kiểu char là bao nhiêu byte?
A. 1
B. 2
C. 4
D. 8
Khai báo biến nào sau đây là SAI?
A. double d = 3.14;
B. int num = 10;
C. long lint = 8;
D. short int = 5;
Khai báo nào sau đây là ĐÚNG?
A. signed a;
B. sign double d;
C. unsign int i;
D. longth t;
Biến toàn cục là gì?
A. Biến khai báo trong thân một hàm hoặc một khối lệnh.
B. Biến khai báo trong thân main, hoặc bên ngoài tất cả các hàm.
C. Cả hai đáp án đầu đúng.
Biến cục bộ là dạng biến gì? Chọn câu trả lời đúng nhất.
A. Là biến khai báo trong thân hàm main
B. Là biến khai báo trong thân một khối lệnh
C. Là biến khai báo trong thân một hàm
D. Là biến khai báo trong một hàm hoặc một khối lệnh
Chuỗi ký tự (string) là gì?
A. Các giá trị không phải là số và có độ dài là 1
B. Các giá trị số lớn hơn 0
C. Các biến có giá trị true hoặc false
D. Các giá trị cả chữ và số, nằm trong 2 dấu nháy “” và kết thúc với ký tự null
Lệnh nào sau đây là SAI?
A. string s = 1234;
B. string s (“Hello world!”);
C. string s = “Hello world!”;
D. Tất cả đầu đúng
Khai báo nào sau đây là SAI?
A. char c = “a”;
B. int i = 75ul;
C. int i = 0013;
D. int i = 0x4b
Lệnh nào sau đây định nghĩa một hằng giá trị?
A. const PI = 3.1415;
B. #define PI 3.1415
C. #define PI = 3.1415
D. const float PI;
Đoạn lệnh sau có kết quả bao nhiêu?
A. Một giá trị bất kỳ
B. 5
C. 7
D. Lỗi biên dịch
Lệnh nào sau đây là SAI?
A. cout << 120;
B. Không có lệnh sai
C. int x; cout << x;
D. int age = 33; cout << “My age is “ << age << “.\n”;
Nguyên lý của cấu trúc while là:
A. Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện bằng 0.
B. Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện sai.
C. Chương trình sẽ lặp đi lặp lại khối lệnh cho đến khi biểu thức điều kiện đúng.
D. Không có đáp án đúng.
Kết quả đoạn lệnh sau là bao nhiêu?
A. Lỗi biên dịch
B. 0,1,4,9,
C. Lặp vĩnh viễn
D. 0,1,4,
Kết quả đoạn lệnh sau là bao nhiêu?
A. 0,1,4,
B. Lặp vĩnh viễn
C. Lỗi biên dịch
D. 0,1,4,9,
Kết quả đoạn lệnh sau là bao nhiêu?
A. Lỗi biên dịch
B. Lặp vĩnh viễn
C. 0,1,4,
D. 0,1,4,9
Kết quả đoạn lệnh sau là bao nhiêu?
A. Lặp vĩnh viễn
B. 0,1,2,
C. Lỗi biên dịch
D. 0,1,
Kết quả đoạn lệnh sau là bao nhiêu? For (int i = 0,n = 5; n != i; i++,n--) cout << i << “,”;
A. 0,1,2,
B. Lặp vĩnh viễn
C. Lỗi biên dịch
D. 0,1,
Cách khai báo hàm nào sau đây là đúng?
A. <Tên hàm> { Khối lệnh }
B. <Kiểu dữ liệu trả về> <Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh}
C. <Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh }
D. <Kiểu dữ liệu trả về> :<Tên hàm> (Tham số 1, Tham số 2,..) { Khối lệnh}
Thế nào là truyền tham trị? Chọn câu trả lời đúng nhất
A. Truyền bản sao của tham số vào biến. Tất cả các thay đổi của biến được thực hiện bởi hàm không ảnh hưởng đến giá trị của biến bên ngoài hàm.
B. Truyền địa chỉ của biến vào hàm.
C. Truyền giá trị của tham số vào biến.
D. Truyền bản sao của biến vào hàm chứ không phải là bản thân biến
Thế nào là truyền tham biến? Chọn câu trả lời đúng nhất
A. Truyền giá trị của tham số vào biến.
B. Truyền bản sao của tham số vào biến. Tất cả các thay đổi của biến được thực hiện bởi hàm không ảnh hưởng đến giá trị của biến bên ngoài hàm.
C. Truyền địa chỉ của biến vào hàm.
D. Truyền bản sao của biến vào hàm chứ không phải là bản thân biến.
Hàm overloaded là những hàm như thế nào?
A. Các hàm trùng tên nhưng khác về cách khai báo tham số
B. Các hàm có cùng kiểu dữ liệu trả về
C. Không có đáp án đúng
D. Các hàm trùng tham số những khác nhau về tên
Mảng là gì? Chọn câu trả lời đúng nhất
A. Một chuỗi các phần tử cùng kiểu đặt trên các vị trí bộ nhớ khác nhau, trong đó mỗi phần tử có thể tham chiếu thông qua số chỉ mục và tên mảng.
B. Một chuỗi các phần tử khác kiểu được đặt trên các vị trí bộ nhớ liên tiếp nhau, trong đó mỗi thành phần có thể được tham chiếu thông qua số chỉ mục và tên mảng.
C. Một chuỗi các phần tử cùng kiểu được đặt trên các vị trí bộ nhớ liên tiếp nhau, trong đó mỗi thành phần có thể được tham chiếu thông qua số chỉ mục và tên mảng.
D. Không có đáp án đúng