- 論壇徽章:
- 0
|
Designated Initializers (C99)
C99 has added a new capability?designated initializers. This feature allows you to pick and choose which elements are initialized. Suppose, for example, that you just want to initialize the last element in an array. With traditional C initialization syntax, you also have to initialize every element preceding the last one:
int arr[6] = {0,0,0,0,0,212}; // traditional syntax
With C99, you can use an index in brackets in the initialization list to specify a particular element:
int arr[6] = {[5] = 212}; // initialize arr[5] to 212
As with regular initialization, after you initialize at least one element, the uninitialized elements are set to 0.
以上摘自 C Primer Plus 5e |
|