if statement - Why am I getting this output in C++? Explain the logic -
#include <stdio.h> #include <iostream> int main() { if(null) std::cout<<"hello"; else std::cout<<"world"; return 0; } the output above question is:
world
kindly explain me why getting output. not able satisfactory answer after referring several different sources.
null results in false condition. imagine null 0, this:
if(null) would equivalent this:
if(0) thus code become:
#include <stdio.h> #include <iostream> int main() { if(0) std::cout<<"hello"; else std::cout<<"world"; return 0; } where obvious because 0 results false, if condition not satisfied, body of if-statement not executed. result, body of else-statement executed, explains output see.
Comments
Post a Comment