Category: 

What Is a Null Character?

Article Details
  • Written By: Eugene P.
  • Edited By: Angela B.
  • Last Modified Date: 29 August 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
The atmosphere of Jupiter's moon Io collapses every time it is eclipsed by the planet.   more...

September 29 ,  2008 :  The Dow Jones Industrial Average experienced its largest one-day drop in history.  more...

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.

Ad

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.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

exception 'Exception' with message 'error writing captcha: Duplicate entry '2147483647' for key 'PRIMARY'' in /ssd/www/wisegeek/public_html/_core/classes/public/Captcha.php:44
Stack trace:
#0 /ssd/www/wisegeek/public_html/_core/controls/public/ControlDiscussionPostBox.php(324): Captcha->createCaptcha()
#1 /ssd/www/wisegeek/public_html/framework/classes/Control.php(104): ControlDiscussionPostBox->preRender(false)
#2 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): Control->render()
#3 /ssd/www/wisegeek/public_html/tpl/default-nocustom-lu/pages/public/article/article.htm(526): Control->__toString()
#4 /ssd/www/wisegeek/public_html/framework/classes/Control.php(300): require('/ssd/www/wisege...')
#5 /ssd/www/wisegeek/public_html/framework/classes/Control.php(309): Control->requireTpl('pages/public/ar...', Object(PageArticleCom), true)
#6 /ssd/www/wisegeek/public_html/framework/classes/Control.php(131): Control->renderTpl('pages/public/ar...', Object(PageArticleCom))
#7 /ssd/www/wisegeek/public_html/framework/classes/FormDataControl.php(87): Control->renderTemplate()
#8 /ssd/www/wisegeek/public_html/framework/classes/Control.php(109): FormDataControl->renderTemplate()
#9 /ssd/www/wisegeek/public_html/framework/classes/ScriptPage.php(50): Control->render(false)
#10 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): ScriptPage->render()
#11 /ssd/www/wisegeek/public_html/framework/classes/Page.php(97): Control->__toString()
#12 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(443): Page->processRequest()
#13 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(7): PublicFrontController->renderPage()
#14 /ssd/www/wisegeek/public_html/index.php(11): PublicFrontController::run()
#15 {main}