#include <iostream>
using namespace std;
// Callback function implementation
void sensorCallback(int v) {
cout << "DATA " << v;
}
int main() {
int flag, value;
cin >> flag >> value;
void (*callback)(int) = nullptr; // optional callback pointer
if (flag == 1) {
callback = sensorCallback; // register callback
}
if (callback == nullptr) {
cout << "NO CALLBACK";
} else {
callback(value); // safe callback invocation
}
return 0;
}
Explanation & Logic Summary:
nullptr to represent “no callback registered”flag is 1, the callback function address is assignednullptrFirmware Relevance & Real-World Context:
nullptr checks is a fundamental firmware safety pattern
Input
0 10
Expected Output
NO CALLBACK