Embercode
✕
ArraysQuick quiz

Jagged arrays and copies

6 questions. Covers Jagged arrays and copying.

Questions 1 to 5 of 6

  1. 1. What does this program print? ``cpp #include <iostream> #include <vector> using namespace std; int main() { vector<vector<int>> a = {{1, 2}, {3, 4, 5}}; vector<vector<int>> b = a; b[1][2] = 9; cout << a[1][2] << "\n"; } ``
  2. 2. What does this program print? ``cpp #include <iostream> #include <vector> using namespace std; int main() { vector<vector<int>> c = {{7}, {8, 9}, {}}; int count = 0; for (const auto& row : c) { count += static_cast<int>(row.size()); } cout << count << " " << c.size() << "\n"; } ``
  3. 3. True or false: after vector<vector<int>> b = a;, a change to b[0][0] also changes a[0][0].
  4. 4. True or false: a class that holds an int* from new[] and frees it in its destructor, with no copy function written, crashes with a double free when one object is copied into another.
  5. 5. In a loop over row r of a jagged array, what should the inner loop bound be?

5 question(s) left on this page.