+ 26

Are NULL and zero that same thing in C++?

Is there a comparison operator like '===' in PHP?

27th Apr 2017, 12:19 AM
Shaun
Shaun - avatar
35 ответов
+ 32
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
27th Apr 2017, 12:22 AM
Krishneel Nair
Krishneel Nair - avatar
+ 22
Nope, we don't have a ===.
27th Apr 2017, 2:45 AM
Hatsy Rei
Hatsy Rei - avatar
+ 19
What is the difference between NULL and zero: https://www.sololearn.com/discuss/348465/?ref=app
2nd May 2017, 3:46 AM
NimWing Yuan
NimWing Yuan - avatar
+ 15
@kirkschafer Thank you great answer was struggling with null v. zero, no more
27th Apr 2017, 9:30 PM
‎‏‎‏‎Joe
‎‏‎‏‎Joe - avatar
+ 11
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. ☺️
30th Apr 2017, 2:36 AM
Vidya
Vidya - avatar
+ 8
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
27th Apr 2017, 9:15 PM
Kirk Schafer
Kirk Schafer - avatar
+ 8
Null doesn't occupy the memory space, Zero occupy the 1bit space of memory.
30th Apr 2017, 3:17 AM
Tilak Basnet
Tilak Basnet - avatar
+ 6
null means that there is no value found. and 0 means zero but zero is still a value which is zero.
28th Apr 2017, 6:01 AM
Anik Shandhi
Anik Shandhi - avatar
+ 6
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!
28th Apr 2017, 4:12 PM
Free Boro
Free Boro - avatar
+ 6
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.
1st May 2017, 11:39 AM
🇺🇸 Anatoli🇧🇪🇪🇺 ,
🇺🇸 Anatoli🇧🇪🇪🇺 , - avatar
+ 5
we have == comparison operator in c++
29th Apr 2017, 8:54 AM
Abhishek Malakar
Abhishek Malakar - avatar
+ 4
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
30th Apr 2017, 5:37 AM
Runvijay
Runvijay - avatar
+ 4
Null is absence of a value, but any supporting numerics datatype can have the value 0 as a starting point.
1st May 2017, 11:11 AM
VJ-code
VJ-code - avatar
+ 4
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^^)
2nd May 2017, 6:32 AM
Glozi30
Glozi30 - avatar
+ 3
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).
27th Apr 2017, 4:06 PM
Norbivar
Norbivar - avatar
+ 3
Zero is a value of variable, NULL is a macros.
28th Apr 2017, 6:28 PM
Марк Бельды
Марк Бельды - avatar
+ 3
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.
1st May 2017, 9:56 AM
Vishal Ramprasad
Vishal Ramprasad - avatar
+ 3
Null doesn't occupy the memory space, but Zero (0) occupy the 1bit space of memory.
2nd May 2017, 1:27 AM
Mount-everest Nepal
Mount-everest Nepal - avatar
+ 2
No. null has no value and 0 is a value of 0 whether int, string,float, or double
27th Apr 2017, 8:12 PM
Richard
+ 2
Zero is a value but null is not ..
28th Apr 2017, 5:31 PM
wejdan
wejdan - avatar