X hits on this document

174 views

0 shares

0 downloads

0 comments

10 / 63

Copyright ©2004 Pearson Addison-Wesley. All rights reserved.

8-10

Array Initialization(1)

When you declare a variable, its value isn’t initialized unless you specify.

int sum;// Does not initialize sum

int sum = 1; // Initializes sum to 1

Arrays, like variables, aren’t initialized by default

int X[10];  //creates the array, but doesn’t set any of its values.

To initialize an array, list all of the initial values separated by commas and surrounded by curly braces:

int X[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};

The array elements are initialized in the order listed

X[0] == 2

X[4] == 11

Document info
Document views174
Page views174
Page last viewedSun Dec 11 01:12:00 UTC 2016
Pages63
Paragraphs754
Words4119

Comments