A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-122.cpp
1#include<iostream>
2intmain(){
3std::cout<<std::boolalpha;
4int*p=nullptr;
5std::cout<<(p==0)<<"\n";
6std::cout<<!p<<"\n";
7return0;
8}
Conversions
Answer & explanation
Console output
true
true
Why
Comparing a null pointer to the literal 0 is true because 0 is a null pointer constant. Applying ! converts the pointer to bool (null is false) and negates it to true. Both expressions print true under boolalpha, reflecting the pointer-to-bool and null-comparison rules.