What exactly does NULL mean? An example and explanation of it in code, would be cool. But a simple overview is cool too.
Thanks...
What exactly does NULL mean? An example and explanation of it in code, would be cool. But a simple overview is cool too.
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.
Trinity: "Neo... nobody has ever done this before."
Neo: "That's why it's going to work."
c9915ec6c1f3b876ddf38514adbb94f0
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.
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
null = 0. "Real" C++ programmers use 0 not NULL.
Last edited by 7stud; 10-25-2005 at 08:07 PM.
Correction NULL = 0 not nullOriginally Posted by 7stud
Take a look at this
http://faq.cprogramming.com/cgi-bin/...&id=1043284376
"Service of the poor and destitutes is the service of the God"
Normative Changes to ISO/IEC 9899:1990 in Technical Corrigendum 1
Incompatibilities Between ISO C and ISO C++
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!
-"What we wish, we readily believe, and what we ourselves think, we imagine others think also."PHP Code:
sadf
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.
Trinity: "Neo... nobody has ever done this before."
Neo: "That's why it's going to work."
c9915ec6c1f3b876ddf38514adbb94f0
From the faq:
Although, if you can show me that the standard says NULL must be defined as 0 then you would be rightNULL is to be used for pointers only since it may be defined as ((void *)0), this would cause problems with anything but pointers.
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
Bjarne Stroustrup , the father of c++ language, says
and says that c++ programs should not use the NULL macro.In C++, the definition of NULL is 0
Although, if you can show me that the standard says NULL must be defined as 0 then you would be rightOriginally Posted by C++ Standard, 18.1.4Basically 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.Originally Posted by C++ Standard, 4.10.1
I stand corrected
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
BS says:Originally Posted by Ancient DragonSo it's a personal preference.I prefer to avoid macros, so I use 0.