Initialization (programming): Difference between revisions

Content deleted Content added
m re-add merge tag
SmackBot (talk | contribs)
m Date maintenance tags and general fixes: build 414:
Line 1:
{{mergetoMerge to|Declaration (computer science)|date=May 2010}}
In [[computer programming]], '''initialization''' is the assignment of an initial value for a [[data object]]. The way how initialization is performed depends on [[programming language]], as well as type, [[storage class]], etc., of an object to be initialized.
 
Programming constructs which perform initialization are typically called '''initializers''' and '''initializer lists'''.
 
==C family of languages==
Line 8:
In C/C99/C++, an '''initializer''' is an optional part of a [[declarator (computing)|declarator]]. It consists of the '=' character followed by an [[expression (programming)|expression]] or a comma-separated list of expressions placed in curly brackets (braces). The latter list is sometimes called the "initializer list" or "initialization list", although the term "initializer list" is formally reserved for initialization of class/struct members in C++, see below.
 
A declaration which includes initialization is commonly called '''definition'''.
 
Many find it convenient to draw a distinction between the terms "declaration" and "definition", as in the commonly seen phrase "the distinction between a ''declaration'' and ''definition''...", implying that a declaration merely designates a data object (or function). In fact, according to the [[C++ standard]], a definition ''is'' a declaration. Still, the usage "declarations and definitions", although formally incorrect, is common. <ref>''C++ FAQs'', by Cline, Lomow, and Girou, Addison-Wesley, 1999, ISBN 0-201-30983-1.</ref>
 
Examples:
Line 18:
-->
:int i = 0;
:int i2(0);
:int k[4] = {0, 1};
:int j[2] = {rand(), k[0]};
Line 41:
 
==References==
{{reflistReflist}}
 
{{DEFAULTSORT:Initialization (Programming)}}
[[Category:Computer programming]]
[[Category:Programming constructs]]