If NULL and 0 are equivalent as null pointer constants, which should I use?
Null PointersMany programmers believe that NULL should be used in all pointer contexts, as a reminder that the value is to be thought of as a pointer. Others feel that the confusion surrounding NULL and 0 is only compounded by hiding 0 behind a macro, and prefer to use unadorned 0 instead. There is no one right answer. (See also questions 9.4 and 17.10.) C programmers must understand that NULL and 0 are interchangeable in pointer contexts, and that an uncast 0 is perfectly acceptable.
If "NULL" and "0" are equivalent, which should I use?
The C Language FAQMany programmers believe that "NULL" should be used in all pointer contexts, as a reminder that the value is to be thought of as a pointer. Others feel that the confusion surrounding "NULL" and "0" is only compounded by hiding "0" behind a #definition, and prefer to use unadorned "0" instead. There is no one right answer. C programmers must understand that "NULL" and "0" are interchangeable and that an uncast "0" is perfectly acceptable in initialization, assignment, and comparison contexts.
Is a null statement a null pointer?
Infrequently Asked Questions in comp.lang.cNo. A null pointer is a pointer where all of the address bits are zero (no matter what the segment bits are), and can be obtained by typing '(char *) (int) 0'. A null statement is not a pointer to anything. They are not interchangeable, although you can combine them to get an effectively-null statement, such as NULL;. This does not buy you anything. [a] Send large donations, checks, and money orders to the author of the FAQ, or the moderator of the group, whichever you prefer.
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?
Memory AllocationIt's hard to say. The Standard doesn't say that systems can act this way, but it doesn't explicitly say that they can't, either. (Such a ''deferred failure'' implementation would not seem to conform to the implied requirements of the Standard.) The conspicuous problem is that, by the time the program gets around to trying to use the memory, there might not be any. The program in this case must typically be killed by the operating system, since the semantics of C provide no recourse.
This is strange. NULL is guaranteed to be 0, but the null pointer is not?
Frequently Asked Questions: C Language (abridged)A "null pointer" is a language concept whose particular internal value does not matter. A null pointer is requested in source code with the character "0". "NULL" is a preprocessor macro, which is always #defined as 0 (or ((void *)0)).
I'm confused. NULL is guaranteed to be 0, but the null pointer is not?
The C Language FAQThe conceptual null pointer, the abstract language concept defined in question 1.1. It is implemented with... The internal (or run-time) representation of a null pointer, which may or may not be all-bits-0 and which may be different for different pointer types. The actual values should be of concern only to compiler writers. Authors of C programs never see them, since they use... The source code syntax for null pointers, which is the single character "0". It is often hidden behind..
Is a run-time integral value of 0, cast to a pointer, guaranteed to be a null pointer?
All QuestionsHow can I access an interrupt vector located at the machine's location 0? If I set a pointer to 0, the compiler might translate it to some nonzero internal null pointer value.
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
OOPS FAQ - Page 7Latest Answer: NULL pointer is pointer which is not pointing to anything in the memory. NULL is defined as (v...
Should I use symbolic names like TRUE and FALSE for Boolean constants, or plain 1 and 0?
All QuestionsI'm trying to define a few simple little function-like macros such as #define square(x) x * x but they're not always working.
What is this infamous null pointer, anyway?
The C Language FAQThe language definition states that for each pointer type, there is a special value -- the "null pointer" -- which is distinguishable from all other pointer values and which is not the address of any object. That is, the address-of operator & will never yield a null pointer, nor will a successful call to malloc.
How do I "get" a null pointer in my programs?
The C Language FAQAccording to the language definition, a constant 0 in a pointer context is converted into a null pointer at compile time. That is, in an initialization, assignment, or comparison when one side is a variable or expression of pointer type, the compiler can tell that a constant 0 on the other side requests a null pointer, and generate the correctly-typed null pointer value.
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
OOPS FAQ - Page 7Latest Answer: NULL is a macro which contains the value 0 (on most implementations). this is the one used to initia...
