const correctness is marking every entity that shouldn't be modified as const, read-only parameters (const T&), query methods (int value() const), and immutable values, so the type system enforces read-only-ness throughout the program. You design it in from the start because it cascades: a const Sensor& can only call const methods, so if a query method isn't marked const, every caller holding a const reference fails to compile. Retrofitting const onto a mature API means touching everything that calls into it. Done early, it's free and it lets the compiler catch accidental mutations, documents which operations are side-effect-free, and enables passing objects by const& efficiently. It's one of the highest-value, lowest-cost habits in C++.
C++ for Embedded · Interview question
What is const correctness and why design for it from the start?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
const Correctness & constexpr
const propagates read-only intent through your whole API; constexpr moves computation to compile time so lookup tables and config land in flash with zero runtime cost.