Search results
Results From The WOW.Com Content Network
Dereferencing a null pointer is undefined behavior in C, [7] and a conforming implementation is allowed to assume that any pointer that is dereferenced is not null. In practice, dereferencing a null pointer may result in an attempted read or write from memory that is not mapped, triggering a segmentation fault or memory access violation.
It is often abbreviated as NUL (or NULL, though in some contexts that term is used for the null pointer). In 8-bit codes, it is known as a null byte . The original meaning of this character was like NOP —when sent to a printer or a terminal , it has no effect (some terminals, however, incorrectly display it as space ).
A null pointer has a value reserved for indicating that the pointer does not refer to a valid object. Null pointers are routinely used to represent conditions such as the end of a list of unknown length or the failure to perform some action; this use of null pointers can be compared to nullable types and to the Nothing value in an option type.
Null device, a virtual file that discards data written to it, on Unix systems /dev/null Null pointer or reference (sometimes written NULL , nil , or None ), an object pointer (or reference) not currently set to point (or refer) to a valid object
In C and C++, 0 represents the null pointer. As with Boolean values, the C standard library includes a macro definition NULL whose use is encouraged. Other languages provide a specific null or nil value and when this is the case no alternative should be used. The typed pointer constant nullptr has been introduced with C++11.
To expose dangling pointer errors, one common programming technique is to set pointers to the null pointer or to an invalid address once the storage they point to has been released. When the null pointer is dereferenced (in most languages) the program will immediately terminate—there is no potential for data corruption or unpredictable behavior.
A null Animal* pointer is possible, and could be useful as a place-holder, but may not be used for direct dispatch: a->MakeSound() is undefined behavior if a is a null pointer. The null object pattern solves this problem by providing a special NullAnimal class which can be instantiated bound to an Animal pointer or reference.
NULL: Macro expanding to the null pointer constant; that is, a constant representing a pointer value which is guaranteed not to be a valid address of an object in memory. wchar_t: Type used for a code unit in "wide" strings.