
When you use fptr == NULL, you're actually checking if fptr is equal to the special value NULL, which indicates that no file was opened successfully at that pointer.
Basically, fopen() is designed to either:
return a pointer to a
FILEobject representing the file you want to work with,or, if there's an error (like if the file isn't found), it returns
NULL.The value
NULLin this context signals that the pointerfptrdoesn't point to any valid file, allowing you to safely check if the file operation succeeded.
In other words, NULL isn't just an ordinary value; it's actually a special marker that's treated differently from ordinary literals such as 1, 0, "yes", "no", etc.
That's why you can indeed check fptr == NULL but can't do checks such as fptr == "yes" since that's not allowed in pointer operations.
Hope this helps you understand the behavior of NULL and pointers better! Let me know if you have any more questions.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer