← Back to Question List
C++ Code Walkthrough #95
Trace Array Elements Through a Pointer
📄 Code
Read carefully — what does this print?1#include <iostream>23int main() {4 double values[] = {1.5, 2.5, 3.5, 4.5};5 double* p = &values[1];6 std::cout << p[0] << " " << p[-1] << " " << *p << "\n";7 ++p;8 std::cout << p[0] << " " << p[-1] << " " << *p << "\n";9 p[0] = 10.5;10 *(p - 1) = 20.5;11 for (double v : values) {12 std::cout << v << "\n";13 }14 return 0;15}