What exactly does NULL mean? An example and explanation of it in code, would be cool. But a simple overview is cool too. :cool:
Thanks...
Printable View
What exactly does NULL mean? An example and explanation of it in code, would be cool. But a simple overview is cool too. :cool:
Thanks...
Well here's a definition: http://en.wikipedia.org/wiki/Null
Say there is a function that has an extra parameter that you can use to set additional options. If you don't want those additional options you can pass NULL for that parameter. NULL is kind of like a spaceholder for nothing.
I don't think that's quite right. You wouldn't use NULL where a function expects an int, but if the function expects a pointer (and can handle a NULL value) then you could pass NULL.
null = 0. "Real" C++ programmers use 0 not NULL.
Correction NULL = 0 not null :)Quote:
Originally Posted by 7stud
Take a look at this
http://faq.cprogramming.com/cgi-bin/...&id=1043284376
NULL means absolutely nothing ;)
Sentral,
NULL = 0, or hex 0x00000000, or binary 000000000000. Its stated in the compiler, #define NULL 0, try hovering over NULL in Visual C++, u'll see how it defines it. When you set a pointer to NULL you are actually setting it to address 0x00000000 which is a placeholder address that points to nada or shorthand - 0.
7stud,
I use NULL for an int sometimes when I'm lazy. You sayin I'm not a "real" programmer? Them's fightin words!
Not quite right that NULL is kind of like a place holder for nothing? How so? I said kind of because NULL=0 and 0 is important so I wouldn't consider it nothing, although it represents nothing. I usually use 0 if the function is asking for an integer value, but sometimes I use NULL, it all depends.
From the faq:
Although, if you can show me that the standard says NULL must be defined as 0 then you would be rightQuote:
NULL is to be used for pointers only since it may be defined as ((void *)0), this would cause problems with anything but pointers.
Bjarne Stroustrup , the father of c++ language, says
and says that c++ programs should not use the NULL macro.Quote:
In C++, the definition of NULL is 0
Quote:
Although, if you can show me that the standard says NULL must be defined as 0 then you would be right
Quote:
Originally Posted by C++ Standard, 18.1.4
Basically NULL doesn't point to "nothing" because 0 is "something". What it does is points to a location that you know you can't use.Quote:
Originally Posted by C++ Standard, 4.10.1
I stand corrected
BS says:Quote:
Originally Posted by Ancient Dragon
So it's a personal preference.Quote:
I prefer to avoid macros, so I use 0.
:D I see.......ok this makes sense now. I thought it was something totally different. But this is so much better now...thanks.
In my home language(Estonian), NULL means zero. :P
My compiler defines NULL as
but it is an old compiler.Code:#define NULL ((void*)0)
German as well (not my native langauge one Im taking in college)Quote:
Originally Posted by maxorator
English too!
http://dictionary.reference.com/search?q=null