You are on page 1of 3

Luyện tập:

Câu 1: Có mấy cách truyền tham số cho hàm trong c++


A.2
B.3
C.4
D.5
Có 3 cách truyền tham số :
+Truyền bằng tham trị (pass by value)
+Truyền bằng địa chỉ (pass by address hoặc pass by pointer)
+Truyền bằng tham chiếu (pass by reference)

Câu 2: Con trỏ trong c++ dùng để lưu trữ gì?

A.Địa chỉ của ô nhớ (biến)

B.Giá trị của ô nhớ (biến)

C.Cả địa chỉ và giá trị của biến

D.Không câu nào đúng

Câu 3: Đoạn code sau sẽ hiển thị giá trị của i bằng mấy ?

int main()
{
vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++
extension !"};
int i=0;
for (const string& word : msg)
{
i++;
}
cout << i << endl;
A.4
B.5
C.6
D.7
Đáp án là 6 vì dùng for each để duyệt qua vector có 6 phần tử
Câu 4: Tìm lỗi của đoạn code sau:
int main(){
vector<int> msg={4,5,6};
for(const string& word : msg){
cout<<word<<” ”;
}
cout<<endl;
}
Đáp án lỗi : sai ở chỗ string tại vì kiểu dữ liệu của vector là int
Câu 5:
int main() { vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++

extension !"}; int i=0; for (const string& word : msg) { i++; } cout << i << endl;

int main() { vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++

extension !"}; int i=0; for (const string& word : msg) { i++; } cout << i << endl;int main()

{ vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++

extension !"}; int i=0; for (const string& word : msg) { i++; } cout << i << endl;int main()

{ vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++

extension !"}; int i=0; for (const string& word : msg) { i++; } cout << i << endl;int main()

{ vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++

extension !"}; int i=0; for (const string& word : msg) { i++; } cout << i << endl;

int main() { vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++

extension !"}; int i=0; for (const string& word : msg) { i++; } cout << i << endl;

int main() { vector<string> msg{"Hello", "C++", "World","from", "VS Code", "and the C++

extension !"}; int i=0; for (const string& word : msg) { i++; } cout << i << endl;

You might also like