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.
Warm-up questions
Short questions with short answers, each answered in full.
-
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
-
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
-
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
-
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++
-
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
-
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.
-
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
-
- The fingerprints differ from step 1. What do you suspect?
- Would switching to fixed-point maths remove every cause?
- How do you keep it from coming back?
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.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
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
-
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
-
- Which step size would you choose, and why?
- The phone is too slow even for 60 steps a second. Now what?
- Why does the character look jittery on a 90 Hz display?
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
-
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
-
- The sprite also has a scale. Where does the scale matrix go?
- How would you test the transform code?
- Your engine uses row vectors. What changes?
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
-
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
-
- Why is the bug invisible with rotations and uniform scales?
- What if the scale is negative or zero on one axis?
- How do you make the library hard to misuse?
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
-
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
-
- Which fix would you choose for a 16 km by 16 km map, and which for a space game?
- What breaks when you shift the origin?
- Does the GPU need doubles too?
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
-
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
-
- How small must the step be for this ball and this paddle?
- Why cap the time one frame may add, and what does the cap cost?
- Would a higher SetTargetFPS fix the bug?
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
-
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
-
- The comparison passes on your laptop and fails on the build machine. Why?
- How do you show what changed in a failing frame?
- What should never be tested with screenshots?
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
-
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
-
- How would you write a test that catches this bug?
- The player holds a key to charge a jump. Which functions do you use?
- How do you let players remap keys without touching the rules?
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
-
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
-
- Why not one grid of 60-pixel cells for every object?
- The enemies crowd around the player. What changes?
- How would you check that the grid never misses a hit?
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
-
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
-
- How many substeps would you need?
- Why do engines sweep against walls but rarely between two moving bodies?
- Is there a way to never miss without either fix?
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
-
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
-
- Would a smaller time step fix it?
- Why does adding damping only hide the problem?
- When would you choose velocity Verlet instead?
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
-
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
-
- How would a test have caught it before the release?
- What changes if the table is generated from markers?
- What does C++26 reflection change, and what does it not?
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
-
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
-
- How would you reproduce it reliably?
- Why does the bug come and go?
- When is a reference that does not keep the object alive the right choice?
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
-
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
-
- What happens if an exception crosses code built without exceptions?
- How does an engine-style Cast work without RTTI?
- How do you report errors without exceptions so callers cannot ignore them?
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
-
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
-
- The slow frames come exactly once a second. What does that suggest?
- How do you find which part of a slow frame is slow?
- How would you keep the problem from coming back?
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
-
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
-
- How many frames would you spread the writing over?
- What if the state is too big to copy in one frame?
- How do you prove the new save is identical to the old one?
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
-
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
-
- Was removing the allocations wasted work?
- How do you find what only the slow frames do?
- Which number would you put in a test, and how?
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