Safe Sensor nullptr Check

#include <iostream>
using namespace std;

int main() {
    int f;
    int *SensorPointer = nullptr;
    cin >> f;
    if(!(f^1)){
        SensorPointer = new int;
        cin >> *SensorPointer; 
    }
    if(SensorPointer){
        cout << *SensorPointer;
    }
    else{
        cout << "NO SENSOR";
    }

}

Rewrote

 

 

 

 

 

 

 

Upvote
Downvote
Loading...

Input

0

Expected Output

NO SENSOR