|
In [[computing]], a '''null pointer''' (sometimes shortened to '''nullptr''' or '''null''') or '''null reference''' is a value indicating that the [[Pointer (computer programming)|pointer]] or [[reference (computer science)|reference]] does not refer to an [[Object (computer science)|object]]. Programs routinely use null pointers to represent conditions such as the end of a [[List (computing)|list]] of unknown length or the failure to perform some action; this use of null pointers can be compared to [[nullable type]]s and to the ''Nothing'' value in an [[option type]]. |
|
In [[computing]], a '''null pointer''' (sometimes shortened to '''nullptr''' or '''null''') or '''null reference''' is a value indicating that the [[Pointer (computer programming)|pointer]] or [[reference (computer science)|reference]] does not refer to an [[Object (computer science)|object]]. Programs routinely use null pointers to represent conditions such as the end of a [[List (computing)|list]] of unknown length or the failure to perform some action; this use of null pointers can be compared to [[nullable type]]s and to the ''Nothing'' value in an [[option type]]. |
|
A null pointer should not be confused with an [[uninitialized variable|uninitialized pointer]]: a null pointer is guaranteed to compare unequal to any pointer that points to an object. However, in general, most languages do not offer such a guarantee for uninitialized pointers. It might compare equal to other, valid pointers; or it might compare equal to null pointers. It might do both at different times; or the comparison might be [[undefined behavior]]. Also, in languages offering such support, the correct use depends on the individual experience of each developer and linter tools. Even when used properly, null pointers are [[semantic completeness|semantically incomplete]], since they do not offer the possibility to express the difference between "not applicable", "not known", and "future" values.{{cn|date=March 2025}} |
|
A null pointer should not be confused with an [[uninitialized variable|uninitialized pointer]]: a null pointer is guaranteed to compare unequal to any pointer that points to an object. However, in general, most languages do not offer such a guarantee for uninitialized pointers. It might compare equal to other, valid pointers; or it might compare equal to null pointers. It might do both at different times; or the comparison might be [[undefined behavior]]. Also, in languages offering such support, the correct use depends on the individual experience of each developer and linter tools. Even when used properly, null pointers are [[semantic completeness|semantically incomplete]], since they do not offer the possibility to express the difference between "not applicable", "not currently known", and "not yet determined" values.{{cite journal |last1= Toussaint |first1= Etienne |last2= Guagliardo |first2= Paolo |last3= Libkin |first3= Leonid |last4= Sequeda |first4= Juan |title= Troubles with Nulls, Views from the Users |journal= Proceedings of the VLDB Endowment |date= 2022 |volume= 15 |pages= 2613–2625 |doi= 10.14778/3551793.3551818}} |
|
In systems with a [[tagged architecture]], a possibly null pointer can be replaced with a [[tagged union]] which enforces explicit handling of the exceptional case; in fact, a possibly null pointer can be seen as a [[tagged pointer]] with a computed tag. |
|
In systems with a [[tagged architecture]], a possibly null pointer can be replaced with a [[tagged union]] which enforces explicit handling of the exceptional case; in fact, a possibly null pointer can be seen as a [[tagged pointer]] with a computed tag. |