- 1

What is the difference between implicit and explicit typecasting in C++ ? Give with example.

20th Sep 2017, 4:32 PM
Brijesh Bisht
Brijesh Bisht - avatar
2 ответов
+ 6
Implicit is where it automatically converts it. For example, lets say that I declared my variable as a double, but I use a normal integer as its value, it'll automatically convert it. Explicit is where you actually use the casting to specify what type it'll convert to or should be. EXAMPLE: double d = 2; (it'll implicitly convert it to 2.0) int d1 = 1; int d2 = 2; float d = (float)d1 + d2; (this will explicitly convert d1 to float, and the operation itself will automatically convert d2 also)
20th Sep 2017, 4:43 PM
AgentSmith
0
Thanks Netkos
20th Sep 2017, 4:50 PM
Brijesh Bisht
Brijesh Bisht - avatar