Learn something new every day
More Info... by email
A null character in computer programming is a character with the value of zero. It is different from the numeral zero, which is part of the standard printed character set. Null is actually a control character with the index of zero. It is used to indicate that a variable, class or pointer is empty, undefined or not initialized. A null also is used in the C programming language to mark the end of a string of characters.
The null character originally was one of a series of special control characters used to communicate with peripheral hardware such as printers or tape drives. The original meaning of null was to instruct a device to do nothing. As technology became more sophisticated, control characters were needed less for interfacing with external devices. The null remained in most character sets, however, at position zero.
Many programming languages use the null character to indicate that a value has not been assigned to a variable, pointer or class. The value of null is often defined within the programming language’s core libraries as the value '/0', which translates into a single blank character. A variable with the value null does not have the value of zero. Zero is a completely different character code, so tests of equivalency between zero and null will show a result of false. This is by design, because zero can be a valid value for a variable.
The programming language known as C uses the null character to great effect to save memory space. The null character is used as the end of a string of characters, also called a null terminated string. This allows the program to store a string with the need for only one extra byte to hold the null terminator. The null character could not be displayed and was not used for any other purpose, so this system worked well.
Languages that came after C started to use null to initialize new variables and classes. Most language specifications actually guarantee that newly declared variables will equal null. Similarly, variables can be assigned the value null to indicate that they have no value or that they do not point to any memory location.
Certain object-oriented languages can use the null character during the process of garbage collection. If a variable holding an instance of a class is set to null, the data become unreachable unless otherwise referenced by another variable. The garbage collection mechanism, which frees memory that was previously being used, detects the now-unreachable data and returns it to the available memory pool. Explicitly assigning a variable to null is sometimes considered a poor programming style.
One of our editors will review your suggestion and make changes if warranted. Note that depending on the number of suggestions we receive, this can take anywhere from a few hours to a few days. Thank you for helping to improve wiseGEEK!