0

I'm struggling to get my head around what is being instantiated here with (*image) (and what to do with it) in this line:

RGBTRIPLE(*image)[width] = calloc(height, width * sizeof(RGBTRIPLE));

I understand what is being assigned - a chunk of memory as an array of RGBTRIPLEs of width width*sizeof(RGBTRIPLE), but what is (*image) doing and how do I use it? I think it's a pointer to the array; in which case am I using it correctly when I pass it to further functions:

void avg(RGBTRIPLE image[])
{
    printf("b image: %p\n", image);
}

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    printf("a image: %p\n", image);

    avg(*image); // defereference image

    return;
}

>> a image: 0x7f4450729010
>> b image: 0x7f4450729010

Is this the correct way to use *image (I was to pass a reference to the original image array to my function avg(), not a copy of the array)?

0

You are right in saying that image points to the array. However:

void avg(RGBTRIPLE image[])

is the same as:

void avg(RGBTRIPLE *image)

so, you're only printing the address pointed to by image[0][0] with:

printf("b image: %p\n", image);

I'm not sure of what you're trying to do by passing the image array to the avg function though.

You must log in to answer this question.

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