39 AnswersNew Answer
anything equal to 0 maybe initialised as 0. meaning, its only applicable to datatypes supporting numerics. NULL on the other hand may mean its empty. like a string, char or any other relative data types
Nope, we don't have a ===.
What is the difference between NULL and zero: https://www.sololearn.com/discuss/348465/?ref=app
@kirkschafer Thank you great answer was struggling with null v. zero, no more
Null basically have NO VALUE. & 0 is a numeric value itself. Null value is empty, undefined or not even initialized. When a variable is null then variable assign no any value, but if variable is 0 then it hold a integer in memory. ☺️
Additional info to "no exact equivalence (===)". I'll just hang back to link pages with digestibly-short explanations + code demo. They demonstrate what the compiler can/can't determine about NULL (the macro result) under different compiler standards, as compared to the actual integer literal 0 and the "null_ptr" type. First, the NULL macro (and its values, depending on C++ version) http://en.cppreference.com/w/cpp/types/NULL Demonstrates literal, integer, nullptr_t, and (if you uncomment the NULL line) that the compiler can't figure out what NULL should mean: http://en.cppreference.com/w/cpp/types/nullptr_t Just for completion: http://en.cppreference.com/w/cpp/language/nullptr
Null doesn't occupy the memory space, Zero occupy the 1bit space of memory.
null means that there is no value found. and 0 means zero but zero is still a value which is zero.
From the Google style guide at: https://google.github.io/styleguide/cppguide.html#0_and_nullptr/NULL "For pointers (address values), there is a choice between 0, NULL, and nullptr. For projects that allow C++11 features, use nullptr. For C++03 projects, we prefer NULL because it looks like a pointer. In fact, some C++ compilers provide special definitions of NULL which enable them to give useful warnings, particularly in situations where sizeof(NULL) is not equal to sizeof(0)." So, it depends on the language definition in use. Anyway, good hint by @Kirk Schafer!
NULL means that it can have any value. At the digital world there is no such thing as zero or a decimal 0. There is a difference in a binary 0 and NULL it self. NULL can be empty or contain a value but it is not necessary.
we have == comparison operator in c++
In Programming, 0 and null have their on significance. 0 treated as number data type value and also treated as false using in a condition. where as null used as special meaning that define a variable hold no value. Most of time, null assigned to object that have no value
Null is absence of a value, but any supporting numerics datatype can have the value 0 as a starting point.
Take a look at this code https://code.sololearn.com/can5PEJjw9D8/?ref=app NULL is just a preprocessor constant which was defined like this : #define NULL 0 i wouldn't be surprised if NULL exists since the beginning of the c language. Then in theory 0 and NULL are exactly the same thing, you can compare and use NULL ptr as if it were an integer. But in practice lot of programmers use the NULL constant only for pointer, so a lot of compiler will think you will do the same and will send you warnings if you use NULL constant as an integer. Now c++ has developped an other, and really null pointer : the nullptr which can really be considered as a pointer, you can compare it to other value, but you can't print it or doing calculations with it (nullptr *5 is incorrect for example). So i suggest you to use nullptr instead of NULL (but keep using 0 for integers^^)
NULL does equal 0 so that's a thing to watch out for with int* and user-defined == operators where 0 on one side might not actually mean a blank / non existing object (null pointer).
Zero is a value of variable, NULL is a macros.
I know it's confusing but null is used to describe the absence of a value i.e nothing. Although zero has no value...it is still an integer.I hope this gave you a better understanding.
Null doesn't occupy the memory space, but Zero (0) occupy the 1bit space of memory.
No. null has no value and 0 is a value of 0 whether int, string,float, or double
Zero is a value but null is not ..