8 questions. Covers Aliasing.
Questions 1 to 5 of 8
cpp #include <iostream> struct Node { int value; Node* next; }; void print_list(const Node* head) { for (const Node* cur = head; cur != nullptr; cur = cur->next) { std::cout << cur->value << " "; } std::cout << "\n"; } int main() { Node c{3, nullptr}; Node b{2, &c}; Node a{1, &b}; Node* head = &a; Node* first = head; Node* second = head->next; first->next = second->next; second->next = first; head = second; print_list(head); return 0; }
a.next = b.next;
head
a
b
c
b.next
/
cpp #include <iostream> #include <vector> int main() { std::vector<int> prices{10, 20, 30}; for (auto p : prices) p += 1; std::cout << prices[0] << ' '; for (auto& p : prices) p += 1; std::cout << prices[0] << ' ' << prices[2] << '\n'; std::vector<int> copy = prices; copy[1] = 0; std::cout << prices[1] << ' ' << copy[1] << '\n'; return 0; }
std::vector<int>& alias = original;
alias
original
Type your answer.
cpp #include <iostream> int main() { int x = 10; int& r = x; int* p = &x; int y = r; r = 20; *p += 5; std::cout << x << ' ' << y << ' ' << r << '\n'; return 0; }
5 question(s) left on this page.
Typed answers ignore extra spaces and, for most questions, capital letters.