I'm having a brainfart wrapping my head around the use of pointers when trying to pass a reference to the image 2D array in a helper function that I created to assist in the blur effect.

Here's blur:

void blur(int height, int width, RGBTRIPLE image[height][width])
    for (int row = 0; row < height; row++)
        for (int col = 0; col < width; col++) {
            RGBTRIPLE *avgPx = getAverageRGB(row, col, &image[height][width]);

            // Assign the current pixel the average for each color.
            if (avgPx != NULL)
                image[row][col].rgbtBlue    = avgPx->rgbtBlue;
                image[row][col].rgbtGreen   = avgPx->rgbtBlue;
                image[row][col].rgbtRed     = avgPx->rgbtRed;


The helper function I created called getAverageRGB goes like this:

RGBTRIPLE *getAverageRGB(int row, int col, const RGBTRIPLE *image[row][col])

If I understand correctly in the helper function I'm requesting using a pointer to the image[row][col] Array of pointers, so in blur I pass it by reference using &, however I keep getting this compilation error:

error: incompatible pointer types passing 'RGBTRIPLE *' to parameter of type 'const RGBTRIPLE *(*)[*]' [-Werror,-Wincompatible-pointer-types]

Could you guys/girls help me make sense of this? Thanks.

2 Answers 2


The usual thing when passing an array to a function is to do it with a pointer, the question is that the name of the array is already a pointer. Therefore according to my experience your function should be:

getAverageRGB(row, col, image);
  • Thanks. I ended up trying this as well but still got compilation issues. Decided at the end to add all the logic inside of the blur function, as other options involved failures in compilation or passing by the image by value which would hurt the space complexity in a nested loop.
    – Alex
    May 18, 2021 at 5:16

I would suggest you manually taking the average of each section to be honest.
Just don't forget to round at the very end after you've dealt with every decimal and double.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .