Your firmware supports an optional sensor represented by a pointer.
nullptrBased on input, safely handle the pointer and print the correct output.
Steps:
flagflag:0 → no sensor connected → pointer remains nullptr1 → sensor connected → dynamically allocate memory and read the sensor value"NO SENSOR" if the pointer is nullptrInput Format:
flagflag == 1, a second integer follows representing the sensor readingOutput Format:
"NO SENSOR" (exact, uppercase, no extra spaces), or
Example 1
Input:
0
Output:
NO SENSOR
Example 2
Input:
1 35
Output:
35
Constraints:
nullptr to represent a missing sensorflag values must not cause undefined behavior
Input
0
Expected Output
NO SENSOR