By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,465 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,465 IT Pros & Developers. It's quick & easy.

array init

P: n/a
Is it possible for an array to be initialised like this:

int arr[10] = { 0..9 };

So that the array holds 0 to 9 after that?
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Servé Laurijssen wrote:
Is it possible for an array to be initialised like this:

int arr[10] = { 0..9 };

So that the array holds 0 to 9 after that?


Nope, at least not that convenient. So, it's back to

int i;
int arr[10];
for (i = 0; i < sizeof arr/sizeof arr[0]; i++)
arr[i] = i;

You probably could provide a macro which is replaced by something
like that but I'd advise against that.
If you have several lengthy manual initialisations like that, put
them in a separate functions.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #2

P: n/a
Servé Laurijssen wrote:
Is it possible for an array to be initialised like this:

int arr[10] = { 0..9 };

So that the array holds 0 to 9 after that?


Not in that way. If you omit the size you can.

int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

The same can be done with any of the basic types.

-Joe
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.