Dayrvia
C++

C++ · Practice questions

Try 8 questions on C++, then read the explanations and review the related concepts.

Practice questions

Choose an answer and move to the next question. Grade the last one to see explanations and review links.

8 questions
Q1 What does v.size() return?
std::vector<int> v{3, 4};
v.push_back(9);
Q2 What is a after the assignment?
int a = 6;
int b = a;
b = 1;
Q3 What value does n hold?
int n = 2;
int& r = n;
r += 4;
Q4 Which values does v contain afterwards?
std::vector<int> v{1, 2};
for (int x : v) x += 3;
Q5 Which parameter reads a large vector without copying or allowing mutation through it?
Q6 What happens here?
std::vector<int> v;
v.at(0);
Q7 Which pointer now owns the integer?
auto a = std::make_unique<int>(9);
auto b = std::move(a);
Q8 What happens to the allocated integer on normal return?
void run() {
    auto p = std::make_unique<int>(4);
}
Original practice questions written for Dayrvia.