Code Room
Code reviewMedium
Question
Review this C++ function that caches a reference into a vector.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
#include <vector>#include <string> std::string& head_of(std::vector<std::string>& v) { return v.front();} void process(std::vector<std::string>& names) { std::string& first = head_of(names); for (int i = 0; i < 1000; ++i) { names.push_back("appended-" + std::to_string(i)); } // later, log the first name printf("first=%s\n", first.c_str());}Run or narrate your approach, then ask the coach.