Your question is Memory Layout in C. 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).
You're interviewing for an ML Engineer role at Qualcomm, working on model inference that runs on a DSP with a tight, well-defined memory map. Your interviewer hands you this small C program and asks you to reason about where each variable actually lives at runtime.
int global_counter = 10;
static int cached_threshold;
char *label = "qualcomm_dsp_model";
int compute_score(int input)
{
int local_result;
static int call_count;
int *heap_buffer = malloc(sizeof(int) * 4);
call_count = call_count + 1;
local_result = input * global_counter;
heap_buffer[0] = local_result;
return heap_buffer[0];
}
int main(void)
{
int stack_value = 42;
int result = compute_score(stack_value);
printf("%d
", result);
return 0;
}
For each of these, say which memory region it lives in (stack, heap, initialized data segment, BSS, or read-only/text segment) and why: global_counter, cached_threshold, the label pointer itself versus the string it points to, local_result, call_count, the heap_buffer pointer itself versus what it points to, and stack_value. Also say what happens to call_count's value across multiple calls to compute_score, and why that differs from local_result.