One of the key benefits of type casting is that you know how the compiler will treat your variables. In the classic example:
var x = 5
var y = "37"
var z = x + y
Some compilers would treat both variables as strings and concatenate them so x+y="537" whilst others would convert the string to an integer and result in x+y=42.
By defining types you know exactly what type of data is stored and how it is treated. It is also more efficient since the memory assigned to the variable will be sized according to the data it will hold, so smaller data types will take up less memory.
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Offline 1,260 posts
since Aug 2009