+ 3

What is the diffrence between type conversion and type casting?

It would be great if you explain with an example :P

2nd Aug 2017, 2:19 PM
Viraj Singh
Viraj Singh - avatar
2 Answers
+ 2
Basically conversion is automatic and lossless. For example you define something like this: float a = 5; then compiler converts 5 to 5.0 so int to float. Casting is something what coders do on themselves. For example you have function which returns 5 and then you want to divide it by 2. If you type a = 5/2 you will get 2 as a result. So you have to cast 5 to 5.0 (int to float) manually by: a = (float)5/2 after that you will receive desired 2.5 Of course it's just a fraction of this subject but it should be enough for now. Read manual for deeper understanding. :)
10th Aug 2017, 8:34 PM
Grzegorz Skryty
Grzegorz Skryty - avatar