Initialization (programming): Difference between revisions

Content deleted Content added
Initializer list: formatting, concision
Initializer: C++ does not allow designated initializers. Added citation.
Line 5:
==C family of languages==
===Initializer===
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'''.
Line 21:
char tx[3]="fa";
char ty[2]="fa";
struct point {int x; int y;} p = {7, 13};
</source>
 
C only example, using designated initializers:<ref name="bk21st">{{cite book | last = Klemens | first = Ben | authorlink = Ben Klemens | title = 21st Century C | publisher = [[O'Reilly Media]] | date = 2013 | isbn = 1449327141 }}</ref>
<source lang="c">
struct point {int x; int y;} p = { .y = 13 , .x = 7 };
</source>