#include <iostream>
using namespace std;
int main() {
int flag;
cin >> flag;
int* sensorPtr = nullptr;
if (flag == 1) {
sensorPtr = new int;
cin >> *sensorPtr;
}
if (sensorPtr == nullptr) {
cout << "NO SENSOR";
} else {
cout << *sensorPtr;
}
delete sensorPtr;
return 0;
}
Explanation & Logic Summary:
sensorPtr starts as nullptr to indicate absence of hardwarenullptr check prevents unsafe dereferencingdelete on a null pointer is safe and deterministicFirmware Relevance & Real-World Context:
nullptr cleanly represents unavailable hardware
Expected Output
NO SENSOR