Hello,

Im looking at this weird little code fragment I stumbled upon the other day
and I cant figure out how it works.
OK, I get the picture how the array is filled up to the fourth index, but that descending part is evil. And weird. :)

#include<stdio.h>
int main(void)
{
    int p[10];
    int i;
    for(i=0;i<10;i++)
    {
        p[i]=9-i;
        printf("%d",p[i]);
        }
    printf("\n");
    for(i=0;i<10;i++)
    {
        p[i]=p[p[i]];
        printf("%d",p[i]);
        }
    getchar();
    return 0;
}

I'm guessing its the p[p] part. Well its simple if you break it down..

We'll look at the inner p which just returns the i-th element of the array. The value from the inner p is used as the 'index value' of the outer p[index value]. Its a little unorthodox to use an array this way.

Ooops I double posted by accident...Can a moderator remove this one..Thanks.

Edited 6 Years Ago by gerard4143: n/a

Yeah, I reckon it is. Anyways thank u for your help m8, much appreciated.
Cheers:)

Woo. what is this thing? Some kind of clue to puzzle or is it a array filler

_________________________________________
Barhocker : Hier finden Sie eine sehr gro├če Auswahl an Barhocker Internationaler Versand oder Abholung in Berlin.

Edited 6 Years Ago by smellissa: n/a

This question has already been answered. Start a new discussion instead.