Your question is What C Function Calls Produce. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Infineon's embedded team likes to test candidates on exactly how C arrays, pointers, and static locals behave, since firmware code leans on all three constantly. Here is the code.
#include <stdio.h>
void modify(int arr[], int size) {
for (int i = 0; i < size; i++) {
arr[i] = arr[i] * 2 + i;
}
}
int compute(int a, int b) {
static int calls = 0;
calls++;
return (a + b) * calls;
}
int main(void) {
int data[5] = {1, 2, 3, 4, 5};
modify(data, 5);
int x = compute(2, 3);
int y = compute(2, 3);
printf("data: ");
for (int i = 0; i < 5; i++) {
printf("%d ", data[i]);
}
printf("
");
printf("x=%d y=%d
", x, y);
return 0;
}
What do these function calls produce? Trace the program by hand and give the exact output, explaining your reasoning for each value.