Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

C++ Module 22

C++ for game development interview questions

Interview questions on C++ for game development: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

23 questions: 6 warm-ups and 17 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    Why do games update their physics with a fixed timestep instead of the measured frame time?

    Answered in the lesson A C++ game loop: fixed timestep and determinism

  2. Fresher

    What do the dot product and the 2D cross product of two vectors tell a game, and which one says whether an enemy is to the player's left?

    Answered in the lesson Game maths in C++: vectors and matrices

  3. Fresher to mid

    Why should a game's rules live in code that never calls raylib or any other window library?

    Answered in the lesson raylib 6.0 in C++: a window, drawing and input

  4. Fresher to mid

    What are the broad phase and the narrow phase of collision detection, and why do games split the work in two?

    Answered in the lesson Collision detection and physics in C++

  5. Fresher to mid

    What is reflection in a game engine, and what does the engine use it for?

    Answered in the lesson C++ in Unreal, Godot and custom engines

  6. Fresher to mid

    How long is the frame budget at 60 and at 144 frames a second, and why do teams give each system a share of it?

    Answered in the lesson Frame budgets in C++ games: measure and profile

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    A multiplayer game sends only the players' inputs and runs the same fixed-step simulation on every machine. After an update, players on the Windows and macOS builds fall out of sync within a minute. How do you find the cause, and how do you stop it happening again?

    What it tests
    The sources of non-determinism in C++ (floating-point contraction and options, library distributions, iteration order, uninitialised data), per-step state checksums, and bisecting a desync with replays.
    First step
    Make the divergence measurable before guessing: have every machine hash the simulation state after each step and send the hash with its inputs. The first step whose hashes differ shows when the machines diverged, a hash per system shows where, and a recording of that session reproduces it at one desk.
    Follow-ups

    From the lesson A C++ game loop: fixed timestep and determinism

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  2. Fresher to mid

    On low-end phones your game runs at 25 fps, and players there cannot clear a jump that is easy at 60 fps. The loop moves the physics forward by each frame's duration. Explain the bug, redesign the loop, and say what your design costs.

    What it tests
    Why a variable timestep changes physics results, the accumulator loop, interpolation and its latency, and keeping slow devices out of the spiral of death.
    First step
    Show the bug with numbers first: integrate the same jump with steps of 1/25 s and 1/60 s and compare the peaks. Semi-implicit Euler loses height in proportion to the step, so long frames give lower jumps, which points to taking the physics step away from the frame time.
    Follow-ups

    From the lesson A C++ game loop: fixed timestep and determinism

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Fresher to mid

    A sprite should spin about its own centre. In your code it swings in a wide circle around the corner of the screen, and when you reverse the order of the matrices it flies off the screen. Explain both bugs and write the transform that is right.

    What it tests
    Rotation about the origin against rotation about a pivot, reading a matrix product in the right order, and debugging transforms with worked numbers.
    First step
    Write down where one corner of the sprite should end up after a quarter turn, then apply each candidate product to it by hand. A rotation matrix turns about the origin, so the code must move the pivot there first, and the order of the product decides whether that happens.
    Follow-ups

    From the lesson Game maths in C++: vectors and matrices

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Mid to senior

    After an artist stretches a level to twice its width, balls bounce off sloped walls at wrong angles and some pass through them. Flat floors and upright walls still behave. What is wrong in the maths, and how do you fix it in the engine?

    What it tests
    Which matrix keeps a normal perpendicular to a stretched surface and why, why only non-uniform scales expose the bug, and how to fix and test it in a maths library.
    First step
    Measure the angle between a stretched slope and its transformed normal: it should be 90°. Floors and upright walls line up with the stretch axes, so their normals survive any scale; a slope does not, which points at the way normals are transformed.
    Follow-ups

    From the lesson Game maths in C++: vectors and matrices

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Mid to senior

    In an open-world game, vehicles 80 km from the world's origin shake on screen, and a door that opens 1 mm per frame never moves. Positions are floats in metres. Explain both symptoms with numbers, and compare three fixes.

    What it tests
    Float spacing as a function of magnitude, why small increments vanish, and the trade-offs of double positions, a floating origin and sector coordinates.
    First step
    Before choosing a fix, work out how far apart neighbouring floats are at 80 km, from the 24 significant bits a float has. Then compare that spacing with the door's 1 mm step and with how far a vehicle moves between two frames: both symptoms follow from that one number.
    Follow-ups

    From the lesson Game maths in C++: vectors and matrices

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Fresher to mid

    Players report that after they drag the game window, the ball sometimes flies straight through the paddle. The loop calls update(game, input, GetFrameTime()) once per frame. Explain the bug with numbers, and fix it.

    What it tests
    Frame time as a step size, distance moved per step against the size of what must be hit, and a fixed-step loop with a cap.
    First step
    Work out how far the ball moves in the longest frame. At 300 pixels a second, a frame of 150 ms is a jump of 45 pixels. Compare that with how far the ball can travel while it still overlaps the paddle.
    Follow-ups

    From the lesson raylib 6.0 in C++: a window, drawing and input

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Mid to senior

    Your build machines have no display. How would you test a raylib game's drawing code automatically, and what can make a pixel comparison fail, or pass when it should not?

    What it tests
    Separating rules from rendering, drawing without a window, deterministic frames, and the limits of reference images.
    First step
    Split the question in two. Behaviour, such as scoring and collisions, is tested on the game state with no rendering at all. Only what pixels alone can show needs frames: draw scripted frames without a window and compare them with stored references.
    Follow-ups

    From the lesson raylib 6.0 in C++: a window, drawing and input

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Fresher to mid

    In a raylib game, the pause key sometimes works and sometimes seems to do nothing, yet every test of the pause rule passes. What is the likely bug, and how do you structure input so that tests would catch it?

    What it tests
    Level-triggered against edge-triggered input, mapping keys to game actions, and testing the boundary between the window layer and the rules.
    First step
    The rule is tested, so look at the code that feeds it: which raylib function reads the key, and what it reports on each frame while the player holds the key down.
    Follow-ups

    From the lesson raylib 6.0 in C++: a window, drawing and input

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  9. Mid to senior

    A top-down shooter has 5,000 bullets of radius 2, 200 enemies of radius 30 and a 4,000 × 4,000 pixel arena. Bullets never hit each other. Design the broad phase, choose the cell size, and estimate the tests per frame.

    What it tests
    Pruning pairs that cannot collide, sizing cells when objects differ in size, and estimating the work from densities before writing code.
    First step
    List the pairs that matter. Every pair of the 5,200 objects is 13.5 million tests, but only bullet and enemy pairs can collide: 1,000,000. Then store only the enemies in a grid and let each bullet look up the cells around it.
    Follow-ups

    From the lesson Collision detection and physics in C++

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  10. Fresher to mid

    In a 2D game, bullets of radius 2 fired at 3,000 pixels a second sometimes pass through walls 8 pixels thick. The physics runs 60 steps a second. Explain why with numbers, and compare two fixes.

    What it tests
    Tunnelling as a question of distance per step, substeps against swept tests, and what each costs.
    First step
    Compute the distance per step: 3,000 / 60 = 50 pixels. Then compute how far the bullet's centre can travel while the bullet still overlaps the wall, and compare the two.
    Follow-ups

    From the lesson Collision detection and physics in C++

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  11. Mid to senior

    A camera follows the player on a spring. Over a minute it swings wider and wider until it flies off. Each step, the code works out the spring force at the camera's position, moves the camera by its velocity, then changes the velocity by that force. What is wrong, and what do you change?

    What it tests
    Recognising explicit Euler, why it adds energy to oscillators, semi-implicit Euler as the fix, and the roles of the time step and damping.
    First step
    Look at the order of the two updates, then run the spring alone, without damping, for a minute. If its amplitude grows step after step, the integrator itself adds energy, whatever the frame rate.
    Follow-ups

    From the lesson Collision detection and physics in C++

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  12. Mid to senior

    After a release, players say the coins they earn are gone whenever they reload a save. The coins member was added to a class whose properties are registered with a hand-written macro list. Explain the failure, and how you would make it impossible.

    What it tests
    How a property table falls out of step with its class, testing save and load round trips, and generating the table instead of writing it.
    First step
    Look at the class's registration, not at the save code: if the new member has no line in the list, generic code never sees it, so it is neither saved nor loaded, and nothing warns at compile time.
    Follow-ups

    From the lesson C++ in Unreal, Godot and custom engines

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  13. Mid to senior

    In an engine with a tracing garbage collector, a character's spare weapon sometimes reports nonsense damage, and now and then the game crashes. The spare is held by a plain pointer member of the character. Diagnose the bug and fix it.

    What it tests
    How a tracing collector decides what is alive, why references must be visible to it, and how to reproduce the bug with a sanitizer.
    First step
    Ask how the collector finds references. If it follows only the pointers its classes list, a pointer it does not know about keeps nothing alive, so the weapon can be freed while the character still points at it.
    Follow-ups

    From the lesson C++ in Unreal, Godot and custom engines

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  14. Senior to staff

    Your engine is built without exceptions and RTTI. A teammate wants both switched on so that a new library can throw and use dynamic_cast. What do you check, what would it cost, and what do engines use instead?

    What it tests
    What -fno-exceptions and -fno-rtti change, how engines replace dynamic_cast and exceptions, and how to contain a library that needs them.
    First step
    Separate the two questions: does the library need the features across its interface, or only inside itself? If only inside, switch them on for that one module and stop exceptions at its boundary.
    Follow-ups

    From the lesson C++ in Unreal, Godot and custom engines

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  15. Mid to senior

    Your game averages 9 ms a frame against a 16.7 ms budget at 60 frames a second, yet players report stutter. What do you measure, and how do you find the cause?

    What it tests
    Frame-time distributions against averages, percentiles and frames over budget, and narrowing a spike down to a system and then to code.
    First step
    Stop looking at the average. Record every frame's time for a few minutes of play and report the median, the 95th and 99th percentiles, the slowest frame and the count of frames over budget; then look at when the slow frames happen.
    Follow-ups

    From the lesson Frame budgets in C++ games: measure and profile

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  16. Mid to senior

    Saving the world once a minute causes a 40 ms hitch at 60 frames a second. Design a fix that removes the hitch and keeps every save consistent, with the costs of your design.

    What it tests
    Spreading work across frames, consistency with a frozen copy, latency and memory costs, and proving the result unchanged.
    First step
    Separate taking the snapshot from writing it. The hitch is the writing; the consistency only needs the state of one moment. Ask how long a copy of the saved state takes compared with the 40 ms of writing.
    Follow-ups

    From the lesson Frame budgets in C++ games: measure and profile

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  17. Senior

    A teammate removed every heap allocation from the frame loop. The median frame got a third faster, but the 99th-percentile frame time did not change at all. How can that be, and what do you do next?

    What it tests
    The difference between what sets the typical frame and what sets the slowest frames, and measuring per part of the frame before optimising.
    First step
    The two numbers describe different frames. The median is set by the work every frame does; the 99th percentile by the slowest 1 % of frames. Find what only the slow frames do, by timing each part of the frame separately.
    Follow-ups

    From the lesson Frame budgets in C++ games: measure and profile

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes

All C++ interview questions · The C++ track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.