# Another newbie Pointer/Array question!

• 09-17-2007
031003b
Another newbie Pointer/Array question!
I am having trouble interpreting certain snippets in the code below (the omitted code is hardware specific code).

I have had a look on the tutorial regarding pointers & arrays but still couldn't figure it out.

I have listed the code with comments of my current understanding of each statement and would be much obliged if someone could clarify what they actually do.

Thanks.

Code:

```int *perform(int *w)              //perform takes pointer to an int as arg & returns the same type       {             float *out[1];            // An array of pointers to floats with 1 element                           int n = (int)(w[3]);    //  Why does w become an array suddenly??               out[0] = (float *)(w[2]);    // Array cast to type pointer to float ....               *out[0]++=0;                  //  Does this set each element in out[] to 0 on each cycle? what relevance does the * have here?```
• 10-04-2007
TriKri
Code:

`int *perform(int *w)              //perform takes pointer to an int as arg & returns the same type`
w is a pointer to an int. Arrays is reached this way; a pointer to the first element is used to reach all arrays. In reallity, writing myarray[i] is simply the same as writing *(myarray + i). Every array that is not allocated when entering the scope Is created by calling some allocating function like malloc or calloc. Those functions really returns a pointer to the first element so you got to store a pointer to the array to be able to reach it.

In this case you will get an int by calling w[i] since w is of the type pointer to int, on the other hand I have no idea why they typecast an int to a float*. Maybe they are float pointers stored as ints, that would explain why they try to reach an object through out[0]. Where did you get the code?