#include <iostream>
using namespace std;
// Compile-time temperature lookup table
constexpr int TEMP_TABLE[6] = { -40, -10, 20, 50, 80, 120 };
int main() {
int idx;
cin >> idx;
cout << TEMP_TABLE[idx];
return 0;
}
Explanation & Logic Summary
TEMP_TABLE is declared as constexpr, so it is evaluated entirely at compile timeO(1)) lookupFirmware Relevance & Real Embedded Meaning
In memory-constrained embedded systems (8 KB–32 KB MCUs):
constexpr tables save RAM by residing in FlashThis pattern is commonly used in:
Using a non-constexpr array would:
For these reasons, constexpr lookup tables are standard practice in production embedded firmware.
Input
0
Expected Output
-40