Follow a callback through repeated calls

A callback is a function supplied to another function for that receiving function to invoke. Execute this C program once from the shown initial state. Immediately before main returns, find the local variable result and the global variable calls. Give both as exact integers with zero decimal places.


C
int calls = 0;

int offset(int value) {
    calls += 1;
    return value + 5;
}

int combine(int value, int (*fn)(int)) {
    int a = fn(value);
    int b = fn(a);
    return a + b;
}

int main(void) {
    int result = combine(4, offset);
    return result;
}
Your answers

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: