+ 1
What is the difference between this:
#include <iostream> int main() { int b = 2; double a = b; std::cout << a; return 0; } and this: #include <iostream> int main() { int b = 2; double a = (double)b; std::cout << a; return 0; }
2 Respostas
+ 2
In the first program, the type casting is done implicitely - by the compiler - while in the second example, it is explicit.
General:
https://www.quora.com/What-is-the-difference-between-the-implicit-type-casting-and-explicit-type-casting-in-C++
Differences:
https://stackoverflow.com/questions/7099957/implicit-vs-explicit-conversion
C++:
http://www.cplusplus.com/doc/tutorial/typecasting/
+ 2
there isn't difference in the result, the explicit (double) conversion is not necessary.
This is known as a standard conversion. Standard conversions affect fundamental data types, and allow the conversions between numerical types (short to int, int to float, double to int...),