7 questions. Covers Sentinel loops.
Questions 1 to 5 of 7
cpp #include <iostream> #include <vector> int main() { std::vector<int> v = {1, 2, 3}; for (int x : v) { x *= 2; } for (auto& x : v) { x += 10; } for (int x : v) { std::cout << x << ' '; } std::cout << '\n'; }
cpp #include <iostream> int main() { const int sentinel = -1; int x = 0; int total = 0; std::cin >> x; while (x != sentinel) { total += x; std::cin >> x; } std::cout << total << '\n'; }
cpp #include <iostream> int main() { int arr[] = {1, 2, 3}; int* p = arr; for (int x : p) { std::cout << x << '\n'; } }
arr
arr[3]
p + 1
cpp #include <iostream> int main() { const int sentinel = -1; int score = 0; int total = 0; do { std::cin >> score; total += score; } while (score != sentinel); std::cout << "total: " << total << '\n'; }
total
score >= sentinel
count
5 question(s) left on this page.