Variable size two dimensional array in C
<p>So I've been trying to store a PPM file in a program to be manipulated, I successful stored everything up to the colors, I've made progress on the colors. </p>

<p>During asking a question on stack overflow (<a href="https://stackoverflow.com/questions/35269845/for-loop-stops-for-no-reason?noredirect=1#comment58253178_35269845">For loop stops for no reason</a>) I was convinced that my method was a bit shoddy, however I don't understand the reasoning for using the follow:</p>

<pre><code>COLOR (*colors)[width] = malloc( sizeof(COLOR[height][width]) );
</code></pre>

<p>can someone break down exactly what this line of code is doing and explain what type it is. So I can store it in a struct and successful return it. </p>

<p>Example: 
previously I used pointers to pointers, where I allocated a height and for each pointer I allocated a width. This means that for each pointer I could create a color, increment it along the width until Im at the end, then reset the pointer and increment the height and loop. After I got the full image I return it to store it in the follow:</p>

<pre><code>typedef struct {
    char code[CODE_LENGTH];
    COMMENT *commentPPM;
    int width, height, max;
    COLOR **colorValues;
} PPM;
</code></pre>

<p>using:</p>

<pre><code>ppmFile-&gt;colorValues = getColors(fd, ppmFile-&gt;width, ppmFile-&gt;height);
</code></pre>

<p>and</p>

<pre><code>typedef struct{
    int red, green, blue;
} COLOR;

COLOR * getNextColor(FILE *fd);

COLOR **getColors(FILE *fd, int width, int height){
    printf("\nentered get colors");
    COLOR **colors = malloc(sizeof(COLOR*)*height);
    printf("\nallocated %d space height",height);

    int i,j;
    for(i = 0; i &lt; height; i++, colors++){
        *colors = malloc(sizeof(COLOR)*width);
        printf("\nallocated %d space width",width);
        for(j = 0; j &lt; width; j++, *(colors++)){
            printf("\nlooping through to get the colors for point (%d,%d)", j,i); 
            //*colors = getNextColor(fd);
        }
        *colors -= width;
        printf("\nmoved the pointer for *colors back %d spaces",width);
    }

    colors -= height;
    printf("\nmoved the pointer for colors back %d spaces",height);

    return colors;
}
</code></pre>