0

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;
}
3
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by smellissa
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.

0

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

Edited by gerard4143: n/a

0

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

0

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 by smellissa: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.