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

C Program Output Behavior

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

Your question is C Program Output Behavior. 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

ALTEN Belgium's embedded systems interviews often include a short C program and ask the candidate to reason through it line by line, since so much embedded work comes down to correctly predicting how integer types actually behave at the byte level, not just what the code seems to say.

#include <stdio.h>

int main(void) {
    unsigned char sensor_min = 20;
    unsigned char sensor_max = 15;
    unsigned char delta = sensor_max - sensor_min;

    printf("delta: %u
", delta);

    int readings[5] = {10, 20, 30, 40, 50};
    int i = 0;
    int sum = 0;

    while (i < 5) {
        sum += readings[i];
        i++;
    }

    short average = sum / 5;
    printf("average: %d
", average);

    unsigned int a = 3;
    int b = -1;

    if (a > b) {
        printf("a is greater
");
    } else {
        printf("b is greater
");
    }

    return 0;
}

Trace through this program and state exactly what it prints to the console, in order. Explain the reasoning behind each line, including any type conversions involved.