Code Room
Code reviewMediumcr-g381
Subject Uninitialized memoryLevel Mid–Senior~18 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this C++ class. The default constructor leaves a field unset on one path.

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
class Sensor {    int id_;    double calib_;   // calibration factorpublic:    Sensor(int id) : id_(id) {        if (id < 0) calib_ = 0.0;   // sentinel for invalid        // valid ids: calib_ left for loadCalibration()    }    double read(double raw) const { return raw * calib_; }};
Run or narrate your approach, then ask the coach.