Visual Studio not assigning float values when stepping over code when debugging

McLellan, Steve 20 Reputation points
2026-07-08T18:31:17.05+00:00

Using:

Microsoft Visual Studio Professional 2019

Version 16.11.57

VisualStudio.16.Release/16.11.57+37327.17

In a C++ project I have a line of code as follows:

float test = 1.0f / 3.0f;

When I set a breakpoint on this line and step over it (F10) it assigns the value of 0.0.

If I set a breakpoint after this line it has a value of 0.3333333 as expected.

Developer technologies | Visual Studio | Debugging

Answer accepted by question author

Nancy Vo (WICLOUD CORPORATION) 7,500 Reputation points Microsoft External Staff Moderator
2026-07-09T03:12:14.39+00:00

Hi @McLellan, Steve ,

Thank you for your question.

Your code and calculation are correct. The reason you see 0.0 when stepping over the line is related to how the debugger displays floating-point values.

When 1.0f / 3.0f is calculated, the result may still be held in a processor register and has not yet been written to the variable's memory. At that moment, the debugger can temporarily show 0.0. Once execution moves to the next line, the value is stored correctly and you will see 0.3333333.

This is expected debugger behavior and does not indicate a problem with your code.

You can refer to these following steps:

  1. Make sure you are running in Debug mode, not Release mode.
  2. Press F10 once more to move to the next line. The variable value should then update correctly.

I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback. Thank you.

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.