Code Room
Code reviewMediumcr-g153
Subject Use after freeLevel Mid–Senior~25 minCommon in Code quality & review interviewsIndustries Software development

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.

Talk through your review
Code to reviewcpp
#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.