Avatar ·

Why should you use static_cast<int>(x) instead of (int)x or int(x) in C++?

Hi! I recently started learning C++ and noticed that in old textbooks and forums, people often use this syntax for type casting: ```cpp double d = 3.14; int i = (int)d; // C-style cast // or int j = int(d); // functional-style cast ``` But then I saw that many experienced developers write like this: ```cpp int k = static_cast(d); ``` And they say this is the "correct" way. I don't quite understand the difference. After all, the result is the same everywhere — the fractional part is discarded. Why write the long `static_cast(x)` if you can just write `(int)x`? Isn't this just code bloat? I'm especially confused about the following points: 1. Are there cases where `(int)x` will do something unexpected, but `static_cast` won't? 2. Is it true that C-style cast is less safe?