X hits on this document

152 views

0 shares

0 downloads

0 comments

11 / 63

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

8-11

Array Initialization(2)

If there are values in the initialization block, but not enough to fill the array, all the elements in the array without values are initialized to 0 in the case of double or int, and NULL in the case of char.

int scores[20]  = {0};         // all 20 elements are initialized to 0

int scores[20]  = {1, 2, 3};  // First 3 elements are initialized to 1, 2,           // 3 and the rest are initialized to 0

If there are values in the initialization block, an explicit size for the array does not need to be specified. Only an empty array element is sufficient, C will count the size of the array for you.

int scores[]  = {20, 10, 25, 30, 40}; // size of the array score is           // automatically calculated as 5

Document info
Document views152
Page views152
Page last viewedThu Dec 08 04:51:26 UTC 2016
Pages63
Paragraphs754
Words4119

Comments