Code Room
Code reviewMediumcr-g382
Subject Dangling pointerLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Review this C++ code that caches a C string for a logging library.

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
struct LogLine { const char* msg; }; LogLine make_line(int code) {    std::string s = "error " + std::to_string(code);    return LogLine{ s.c_str() };   // hand the C string to the sink} auto line = make_line(500);logger.emit(line.msg);
Run or narrate your approach, then ask the coach.