array init

S

Servé Laurijssen

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?
 
M

Michael Mair

Servé Laurijssen said:
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;

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
 
J

Joe Estock

Servé Laurijssen said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top