Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are 'null' and 'NULL' the same?

Tags:

c++

c

Are both null and NULL constants the exact same thing in C/C++?

I've noticed as I write my code in Visual Studio that null and NULL don't get the same syntax highlighting, and the compile outcome is not the same as having null instead of NULL in some sections of the code.


1 Answers

They might be, they might not be.

Both C and C++ define NULL, but in slightly different ways.

null is not part of either standard; it is neither a keyword nor a reserved word, so you can use it as a variable name, class name &c..

The preferred way of denoting pointer null-ness in C++ is nullptr which has type especially designed for pointer nullness.

like image 57
Bathsheba Avatar answered Mar 21 '26 04:03

Bathsheba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!