Gautham Muralidharan

Ranch Hand

Posts: 30

posted 9 months ago

You could add a few additional

For example it could be something like:

Hope it helps!

Kind regards,

Roel

Gautham Muralidharan wrote:Bu I don't understand how I get it. Please explain.

You could add a few additional

`println`statements to see what's going on in the first enhanced

`for`loop (as the second one should be pretty straightforward).

For example it could be something like:

Hope it helps!

Kind regards,

Roel

Gautham Muralidharan

Ranch Hand

Posts: 30

posted 9 months ago

Thanks for the idea Roel. Now I found it.

This is equivalent to

where x will 0,1,2 in each iteration.

As the integer array is not initialized array[x] will always be 0 when x=1 and x=2, which means array[array[x]]=array[0] when x=1 and x=2. So in each iteration, array[0] is assigned with c++, which makes it 2 and the remaining two elements remain zero.

This is equivalent to

where x will 0,1,2 in each iteration.

As the integer array is not initialized array[x] will always be 0 when x=1 and x=2, which means array[array[x]]=array[0] when x=1 and x=2. So in each iteration, array[0] is assigned with c++, which makes it 2 and the remaining two elements remain zero.