Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan

Memory Layout in C

MediumCoding00:00
Practice interviewer
In session
5 left
00:00

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 need to log in / sign up to chat or submit.

Problem

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.