Linked Questions
31 questions linked to/from Do you use NULL or 0 (zero) for pointers in C++?
49 votes
5 answers
177k views
Using NULL in C++? [duplicate]
Possible Duplicate: Do you use NULL or 0 (zero) for pointers in C++? Is it a good idea to use NULL in C++ or just the value 0? Is there a special circumstance using NULL in C code calling from C++...
16 votes
4 answers
5k views
NULL macro or NULL const [duplicate]
I am currently in the process of reading a book on C++, and in this book the author explains that it is better to use a constant rather than NULL macro, but without really explaining why or giving any ...
1 vote
4 answers
959 views
For a NULL pointer, should I use NULL or 0? [duplicate]
Duplicate Do you use NULL or 0 for pointers in C++? When dealing with NULL pointers one can do this if(ptr != NULL){ ... } or this if(ptr != 0){ ... } Are there reasons to prefer one over the ...
3 votes
0 answers
2k views
Is nullptr the same as zero? [duplicate]
I am currently learning C++ and have gotten to pointers. I am struggling to understand the difference between initializing a pointer to zero and initializing it to nullptr, as demonstrated below. int ...
0 votes
0 answers
22 views
Linked List : what should I use in 'while loop' while displaying the linked list as both 0 and NULL giving the same answer? [duplicate]
in display function: both 0 and NULL giving the same answer when using in 'while loop' why? when printing temp it shows 0 after completion of while loop that's why I use 0 as termination condition but ...
692 votes
15 answers
431k views
What is the nullptr keyword, and why is it better than NULL?
We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new nullptr. Well, no need anymore for the nasty macro NULL. int* x = nullptr; myclass* obj = ...
396 votes
11 answers
441k views
What is the difference between NULL, '\0' and 0?
In C, there appear to be differences between various values of zero -- NULL, NUL and 0. I know that the ASCII character '0' evaluates to 48 or 0x30. The NULL pointer is usually defined as: #define ...
56 votes
10 answers
381k views
Check if element found in array c++
How can I check if my array has an element I'm looking for? In Java, I would do something like this: Foo someObject = new Foo(someParameter); Foo foo; //search through Foo[] arr for(int i = 0; i <...
79 votes
6 answers
52k views
Is NULL always zero in C?
I was interviewing a guy for a mid-level software engineering position yesterday, and he mentioned that in C, NULL is not always zero and that he had seen implementations of C where NULL is not zero. ...
27 votes
3 answers
7k views
Is nullptr falsy?
When used as a boolean expression or transformed into a boolean either explicitly or implicitly, is nullptr consistently false? Is this implementation defined or specified in the standard? I wrote ...
5 votes
5 answers
17k views
Why is there a NULL in the C language?
Why is there a NULL in the C language? Is there a context in which just plain literal 0 would not work exactly the same?
1 vote
3 answers
4k views
Why does Python convert 0's into None objects?
I don't quite understand why Python will automatically convert any 0 returned to me by a function into a None object. I've programmed in almost all of the common languages, yet I've never come across ...
0 votes
8 answers
354 views
How many bits to ignore when checking for NULL?
The following crashes with a seg-V: // my code int* ipt; int bool set = false; void Set(int* i) { ASSERT(i); ipt = i; set = true; } int Get() { return set ? *ipt : 0; } // code that I don't ...
0 votes
4 answers
2k views
Undefined variable when initialized in switch statement?
The question itself begs an obvious answer. In any case, here's a snippet of my code... switch(cSet)... case 8:{ //Special Characters finalSet = special; char* charSet = new ...
2 votes
5 answers
1k views
The Meaning of Parentheses after Pointer
I want to ask what does the (0) mean after the pointer i.e. Node* ptr1(0). struct Node { string info; Node * next }; int main() { Node* ptr1 (0), *ptr2 (0), ptr1 = new Node; ptr2 = ...