Category: 

What Is an Empty Array?

Article Details
  • Written By: Eugene P.
  • Edited By: Angela B.
  • Last Modified Date: 21 September 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
Built at the request of Dag Hammarskj√∂ld, the United Nations Headquarters has a meditation room dedicated to silence.   more...

October 1 ,  1890 :  Yosemite National Park was established.  more...

The exact definition of what an empty array is in computer programming is not always clear. One common interpretation is that an array is empty if it has zero elements, although not all computer languages allow an array to be declared in this way. Another interpretation of an empty array is an array in which all of the data elements are either null, zero or undefined, depending on the programming language being used. Certain languages make a distinction between an array that is empty and an array that has not been allocated yet and is equal to null, although other languages might consider an unallocated array to be an empty array.

There are specific instances in which an array can be declared within a program with no elements, meaning it cannot hold any data and is considered an empty array. These are frequently dynamic arrays that can increase the number of elements, because an array with no elements is essentially unusable. In object-oriented programming languages, an empty array can be declared inside an array class wrapper object that is maintaining the array data structure internally. In some scripting and meta-languages, an empty array is passed as a parameter to functions to be filled or assigned values from another data source.

Ad

The other meaning of an empty array is an array that has been initialized so it contains no data, or is filled with values that indicate no data is present. This is because in languages such as C, when memory space for an array is allocated, it still contains any residual data from previous programs or files that might have occupied the space. To empty an array like this, each element must be looped through and then set to a neutral value. This value can be the actual American Standard Code for Information Interchange (ASCII) value zero, which is different from the alphanumerical character zero. It also can be the value for null, meaning no value, which is the same as ASCII zero in some languages.

The purpose of having an empty array is partially for efficiency in some programs. By having an array that is empty, the program can avoid performing pointless or incorrect calculations on the array. It can also prevent a program from accessing an array that does not have a valid memory address, causing a memory access error that could terminate the program. Some computer languages have built-in library or class functions that can easily tell if an array is actually empty according to the language definition.

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}