Repair a callback argument hidden by an alias

A type alias supplies another name for an existing type. This C program intends to call add_two on 9 through run_transform, but its final call has an argument-type error. Which single edit makes the program well-typed and preserves that intended operation? Leave the typedef and function interfaces unchanged.


C
typedef int (*Transform)(int);

int add_two(int value) {
    return value + 2;
}

int run_transform(Transform fn, int value) {
    return fn(value);
}

int main(void) {
    Transform fn = add_two;
    return run_transform(&fn, 9);
}
Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Function Pointers Questions: