R
R
ReD2015-10-21 15:04:09
Programming
ReD, 2015-10-21 15:04:09

Is it possible in C to initialize an array counter with non-consecutive values?

And if so, how?
That is, for example, with specific values ​​from another array.
Need something like this:

int f[F] = {1,12,3,5};
for (int i=f[0]; i<f[F] ; ++i)
{...}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mrrl, 2015-10-21
@Mrl

Do you want the loop to have its counter run through the values ​​in the array?
Nothing will work, you have to write like this:

int f[F] = {1,12,3,5};
    for (int i=0; i<F ; ++i){
         int v=f[i];
         ...
    }

(although it's not exactly C - in C, the variables v and i would have to be described earlier).
Some C# has a foreach loop for this.

D
Dmitry Kovalsky, 2015-10-21
@dmitryKovalskiy

You can initialize the "array count" however you want and change this parameter however you like. The main thing is that the conditions for exiting the loop are fulfilled.

V
Vladimir Martyanov, 2015-10-21
@vilgeforce

What is an "array counter"? If you mean the number inside [] when accessing elements, you can write anything there, the main thing is not to go beyond the boundaries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question