- Học kỳ
- SU2026
- Thời Gian
- 3/8/26
- Loại tài liệu
- FE
- Mã Đề
- PRF193_SU26_RE_604413
PRF193_SU26_RE_604413
Nội dung trong tài liệu
Tài liệu này bao gồm một bộ sưu tập toàn diện các câu hỏi trắc nghiệm ôn tập về lập trình C và C++. Nội dung các câu hỏi xoay quanh nhiều chủ đề quan trọng như lập trình hướng đối tượng, cấu trúc dữ liệu, hàm, con trỏ và các cấu trúc điều khiển. Người học có thể sử dụng các bài kiểm tra này để củng cố kiến thức nền tảng và rèn luyện kỹ năng giải quyết vấn đề. Mỗi câu hỏi đều đi kèm các lựa chọn đáp án chi tiết giúp đánh giá chính xác năng lực học tập.PRF193 SU26 FE Multiple Choice Questions
Question 1
(Choose 1 answer)
Which of the following C/C++ operators has the lowest precedence?
A. &&
B. ||
C. *
D. +
E. =
F. ? :
Question 2
(Choose 1 answer)
What will be the output of the following program?
#include <iostream>
using namespace std;
class R {
int a, b;
public:
R(int x, int y=5): a(x), b{}
int sum() const { return a + b; }
};
int main() {
R r1(2);
R r2(2,3);
cout << r1.sum() << " " << r2.sum();
return 0;
}
A. 7 5
B. 5 7
C. 2 3
D. Compilation error
Question 3
(Choose 1 answer)
Given the code:
int multiply(int a, int b) {
return a * b;
}
Which of the following correctly calls the multiply function?
A. int x = multiply(2, 3);
B. multiply();
C. int x = multiply(2);
D. int x = multiply("2", "3");
Question 4
(Choose 1 answer)
Which loop checks its condition after executing the loop body?
A. do-while loop
B. for loop
C. while loop
D. switch statement
Question 5
(Choose 1 answer)
What is the primary benefit of using functions in programming?
A. Increase the program size
B. Reduce code reusability
C. Break complex programs into manageable parts
D. Make debugging more difficult
PRF193 Multiple Choice Questions
PRF193_SU26_RE_604413 . Multiple Choice
Question 6
(Choose 1 answer)
What will be the output of the following program?
#include <iostream>
using namespace std;
class InlineTest {
public:
inline int add(int a, int b) { return a + b; }
};
int main() {
InlineTest it;
cout << it.add(2,3);
return 0;
}
A. 2
B. 3
C. 5
D. Compilation error
Question 7
(Choose 1 answer)
What is the default underlying type of enumeration constants in C/C++?
A. char
B. int
C. float
D. double
Question 8
(Choose 1 answer)
What will be the output of the following program?
#include <iostream>
using namespace std;
class F {
int &r;
public:
F(int &x): r(x) {}
void set(int v) { r = v; }
};
int main() {
int a = 1;
F f(a);
f.set(5);
cout << a;
return 0;
}
A. 1
B. 5
C. Compilation error
D. Runtime error
Question 9
(Choose 1 answer)
Which of the following is a correct way to call a function named compute that takes no arguments and returns an int?
A. compute;
B. int result = compute();
C. int result = compute;
D. compute(int);
Question 10
(Choose 2 answers)
Which of the following is the correct way to declare a boolean variable in C++?
A. bool isTrue = true;
B. boolean isTrue = true;
C. bool isTrue = 1;
D. bool isTrue = T;
E. All of the others
PRF193 SU26 FE RE Questions 11 to 15
PRF193_SU26_RE_604413 - Multiple Choice
Question 11
(Choose 1 answer)
What will be the output of the following program?
#include <iostream>
using namespace std;
class Base {
public:
virtual ~Base() { cout << "B"; }
};
class Derived : public Base {
public:
~Derived() { cout << "D"; }
};
int main() {
Base *p = new Derived();
delete p;
return 0;
}
A. BD
B. DB
C. B
D. D
Question 12
(Choose 1 answer)
Which of the following correctly declares an integer array of size 5 in C/C++?
A. int arr[5];
B. array int arr = [5];
C. int arr = new int[5];
D. int arr{5};
Question 13
(Choose 2 answers)
Which of the following C/C++ statements correctly initializes an array with the values 1, 2, 3, 4, 5?
A. int arr[] = {1, 2, 3, 4, 5};
B. int arr[5] = {1, 2, 3, 4, 5};
C. int arr[5] = (1, 2, 3, 4, 5);
D. All of the others
Question 14
(Choose 2 answers)
What is the correct syntax to output "Hello, World!" in C/C++? choose 02 correct anwsers.
A. printf("Hello, World!");
B. cout << "Hello, World!" << endl;
C. System.out.println("Hello, World!");
D. echo "Hello, World!";
Question 15
(Choose 1 answer)
What will be the output of the following code snippet?
int x = 10;
if (x > 5)
x = x + 2;
else
x = x - 2;
printf("%d", x);
A. 12
B. 8
C. 10
D. 5
PRF193 SU26 FE Multiple Choice Questions
Question 16
(Choose 2 answers)
What does the following C++ expression evaluate to?
int a = 3;
int b = 4;
bool result = (a < b) || (a == 3);
A. result is true
B. result is false
C. result is 1
D. result is 0
E. result is T
F. All of the others
Question 17
(Choose 2 answers)
Which of the following statements correctly defines a union in C/C++?
A. union Data { int i; float f; char str[20]; };
B. struct Data { int i; float f; char str[20]; };
C. union Data { int i; float f; char str[20]; } data;
D. All of the others
Question 18
(Choose 1 answer)
Which of the following is true about C++ std::string compared to C-style strings?
A. std::string automatically manages memory for string operations.
B. C-style strings are objects with member functions.
C. std::string requires manual handling of the null terminator.
D. C-style strings support operator overloading for concatenation.
Question 19
(Choose 1 answer)
Which loop construct is particularly useful when the number of iterations is determined by user input during the loop's execution?
A. for loop
B. while loop
C. do-while loop
D. foreach loop
Question 20
(Choose 1 answer)
Which of the following control structures is used to execute a block of code multiple times based on a condition?
A. if
B. switch
C. for
D. break
PRF193 Multiple Choice Questions
Question 21
(Choose 1 answer)
What will be the output of the following program?
#include <iostream>
using namespace std;
class D {
double v;
public:
D(double d): v(d) {}
operator int() { return (int)v; }
};
int main() {
D x(3.9);
int y = x;
cout << y;
return 0;
}
A. 3
B. 4
C. Compilation error
D. Runtime error
Question 22
(Choose 1 answer)
Which function closes a file stream?
A. close()
B. finish()
C. stop()
D. end()
Question 23
(Choose 1 answer)
Which operator is used to perform integer division in C/C++?
A. /
B. %
C. //
D. div
Question 24
(Choose 1 answer)
What will be the output of the following C code snippet?
#include <stdio.h>
int main() {
int x = 10;
if (x > 5)
if (x > 15)
printf("High");
else
printf("Medium");
else
printf("Low");
return 0;
}
A. High
B. Medium
C. Low
D. No output
Question 25
(Choose 1 answer)
Which stream class is used for output file operations in C++?
A. ifstream
B. ofstream
C. fstream
D. stringstream
PRF193 Multiple Choice Questions
Question 26
(Choose 1 answer)
What is the effect of calling join() on a std::thread object?
A. It detaches the thread from the main thread
B. It blocks the calling thread until the thread finishes execution
C. It terminates the thread immediately
D. It creates a new thread
Question 27
(Choose 1 answer)
What will be the output of the following code?
#include <iostream>
#include <vector>
using namespace std;
int main() {
int sum, count;
int ia[] = { 1, 3, 2, 5, 7 };
vector<int> v1(ia, ia + 3);
vector<int>::iterator it;
sum = 0;
for ( it = v1.begin(); it != v1.end(); ++it ) {
sum += *it;
}
cout << sum/v1.size() << " ";
cout << endl;
return 0;
}
A. 2
B. 6
C. 2.75
D. The code snippet has an execution error.
Question 28
(Choose 1 answer)
How do you correctly define a function in C that takes two integers and returns their sum?
A. int add(int a, int b) {
return a + b;
}
B. void add(int a, int b) {
return a + b;
}
C. int add(int a, int b);
D. add(int a, int b) {
return a + b;
}
Question 29
(Choose 1 answer)
Which of the following best describes polymorphism in OOP?
A. The ability to create multiple instances of a class
B. The ability of different classes to be treated as instances of the same class through inheritance
C. The ability to hide data within a class
D. The ability to overload operators
Question 30
(Choose 1 answer)
Which of the following is a value-returning function in C++?
A. void display(int a) {
cout << a;
}
B. int add(int a, int b) {
return a + b;
}
C. int main() {
// code
}
D. bool check(int a) {
// no return statement
}
PRF193 Multiple Choice Questions
Question 31
(Choose 1 answer)
How can you ensure that a member function in a base class can be overridden in derived classes to achieve runtime polymorphism?
A. Declare the function as static
B. Declare the function as virtual
C. Use the override keyword
D. Make the function const
Question 32
(Choose 1 answer)
In C/C++, to access the name member of a structure variable Student s, which syntax is correct?
A. s.name
B. s->name
C. s:name
D. s@name
Question 33
(Choose 1 answer)
What is the purpose of the typedef keyword in C++?
A. To create a new type that is identical to an existing type
B. To declare a constant value
C. To define a macro
D. To allocate dynamic memory
Question 34
(Choose 1 answer)
Which of the following is a logical NOT operator in C/C++?
A. ^
B. &&
C. ||
D. &
E. !
F. ~
Question 35
(Choose 2 answers)
Which of the following correctly uses the enum to define colors and assigns Green to a variable c?
A. enum Color { Red, Green, Blue }; Color c = Green;
B. enum Color { Red, Green, Blue }; c = Green;
C. enum Color { Red = 1, Green = 2, Blue = 3 }; Color c = 2;
D. All of the others
PRF193 SU26 FE RE Questions 36 to 40
PRF193_SU26_RE_604413 - Multiple Choice
Question 36
(Choose 1 answer)
What will be the output of the following code?
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int ia[] = { 1, 3, 2, 4, 7, 6, 8 };
vector<int> v1(ia, ia + 3), v2(5);
copy(v1.begin(), v1.end(), v2.begin());
vector<int>::iterator it;
for ( it = v2.begin(); it != v2.end(); ++it) {
cout << *it << " ";
}
cout << endl;
return 0;
}
A. 1 3 2 0 0
B. 1 3 2 4 7
C. 0 0 1 3 2
D. The code snippet has an execution error.
Question 37
(Choose 1 answer)
Given the following overloaded functions:
void show(int x);
void show(double y);
Which version is called by show(5.0);?
A. show(double)
B. show(int)
C. show(char)
D. Compilation error
Question 38
(Choose 1 answer)
Which of the following C++ operators is used for bitwise OR operator?
A. ||
B. |
C. &&
D. &
E. ^
F. !
Question 39
(Choose 1 answer)
What will be the result of compiling and running this program?
#include <iostream>
using namespace std;
class A { public: int x = 5; };
class B : private A {};
int main() {
B b;
cout << b.x;
return 0;
}
A. 5
B. Compilation error
C. 0
D. Runtime error
Question 40
(Choose 1 answer)
What will be the output of the following C++ code snippet?
#include <iostream>
using namespace std;
void modify(int &a) {
a = a + 10;
}
int main() {
int x = 5;
modify(x);
cout << x;
return 0;
}
A. 5
B. 10
C. 15
D. Error
PRF193 Multiple Choice Questions
Question 41
(Choose 1 answer)
What is the size in bytes of the following structure on a system where int is 4 bytes and char is 1 byte?
struct Example {
int a;
char b;
int c;
};
A. 9
B. 10
C. 12
D. 8
Question 42
(Choose 1 answer)
Which of the following is a characteristic of procedural programming?
A. Emphasis on a linear sequence of processes
B. Focus on data encapsulation
C. Use of objects to combine data and behavior
D. Promotion of polymorphism
Question 43
(Choose 1 answer)
What is the maximum value that can be stored in a variable of type char (assuming char is signed and uses 1 byte)?
A. 127
B. 128
C. 255
D. -120
Question 44
(Choose 1 answer)
Which loop structure ensures that the loop body is executed at least once?
A. for loop
B. while loop
C. do...while loop
D. foreach loop
Question 45
(Choose 1 answer)
Which of the following statements correctly creates a pointer to an object car1 of class Car and allocates memory dynamically?
A. Car *carPtr = Car();
B. Car *carPtr = new Car();
C. Car carPtr = new Car;
D. Car carPtr = Car;
PRF193 Multiple Choice Questions
Question 46
Which of the following best describes a class in C++?
A. A function that performs a specific task
B. A blueprint for creating objects, defining attributes and behaviors
C. An instance of an object
D. A type of pointer
Question 47
Which of the following is the correct way to declare an integer variable named count and initialize it to 10 in C++?
A. int count = 10;
B. int count(10);
C. int count{10};
D. All of the others
Question 48
What is the purpose of the return statement in a value-returning function?
A. To terminate the program
B. To exit the function without returning a value
C. To pass the computed value back to the caller
D. To declare a new variable
Question 49
What will be the output of the following program?
#include <iostream>
using namespace std;
class Counter {
public:
static int count;
Counter() { count++; }
static void printCount() { cout << count; }
};
int Counter::count = 0;
int main() {
Counter c1;
Counter c2;
Counter:rintCount();
return 0;
}
A. 1
B. 2
C. 0
D. Compilation error
Question 50
What is the result of the following C/C++ expression?
int a = 5;
int b = 2;
int c = a / b;
A. c is 2.5
B. c is 2
C. c is 3
D. Compilation error
Đính kèm
-
PRF193 SU26 FE RE_001.webp17.6 KB · Lượt xem: 6 -
PRF193 SU26 FE RE_002.webp32.1 KB · Lượt xem: 6 -
PRF193 SU26 FE RE_003.webp24.9 KB · Lượt xem: 5 -
PRF193 SU26 FE RE_004.webp19.8 KB · Lượt xem: 5 -
PRF193 SU26 FE RE_005.webp25.8 KB · Lượt xem: 4 -
PRF193 SU26 FE RE_006.webp29.1 KB · Lượt xem: 4 -
PRF193 SU26 FE RE_007.webp18 KB · Lượt xem: 3 -
PRF193 SU26 FE RE_008.webp29.9 KB · Lượt xem: 3 -
PRF193 SU26 FE RE_009.webp23.8 KB · Lượt xem: 3 -
PRF193 SU26 FE RE_010.webp23.4 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_011.webp32.2 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_012.webp21.1 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_013.webp24.4 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_014.webp25.9 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_015.webp20.5 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_016.webp24.6 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_017.webp27.2 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_018.webp34.8 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_019.webp23.5 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_020.webp21.5 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_021.webp30.7 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_022.webp16.7 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_023.webp17 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_024.webp27.5 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_025.webp19.2 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_026.webp27.9 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_027.webp36.9 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_028.webp26.9 KB · Lượt xem: 2 -
PRF193 SU26 FE RE_029.webp32 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_030.webp25.8 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_031.webp28 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_032.webp21.5 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_033.webp25.1 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_034.webp17.7 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_035.webp30.5 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_036.webp42.7 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_037.webp24.6 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_038.webp18.5 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_039.webp28.7 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_040.webp26.7 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_041.webp22.5 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_042.webp27.7 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_043.webp21.2 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_044.webp20.4 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_045.webp26.5 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_046.webp26.4 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_047.webp23.6 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_048.webp27.1 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_049.webp34.8 KB · Lượt xem: 1 -
PRF193 SU26 FE RE_050.webp20.1 KB · Lượt xem: 5
Sửa lần cuối:


