#include <iostream> using namespace std; // Callback function that prints sensor data 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) { // Assign callback pointer here callback = &sensorCallback; } if(callback == nullptr) cout <<"NO CALLBACK"; else{ callback(value); } // Write nullptr check and callback invocation here return 0; }
Test Cases
Test Results
Input
0 10
Expected Output
NO CALLBACK