Why is the output the same both times?
If you look at this compiled assembly of your code snippet, you can see, that the line in question (intVar = (intVar * 10) / 10;
, line 6 in the input) is completely removed. As Richard Critten mentioned in the comments, this is perfectly legal for the compiler to do in the case of undefined behavior (signed overflow).
In other words: Because the line of code causes undefined behavior, the compiler removes it and it is never executed. As you expected the same value in intVal
before and after this line, you never noticed that it was actually removed.
Image for future reference:

To elaborate on your actual question in the title:
Do intermediate static_cast in c++ have an effect?
Yes, as you can see in your code snippet, the cast to double
allows the CPU do perform the calculation using the IEEE 754 standard for floating point numbers. These numbers are less precise (there are rounding errors) but allow a much wider range of values. In your case, the CPU does:
- Convert the
int
to double
- Multiply it by
10
which results in 1.5e10 (larger than the maximum int
2,147,483,647)
- Divide it by
10
which results in 1.5e9 (fits in a 32 bit int
again)
- Convert it back to
int
(implicit due to the type of intVar
)