Q:

Meaning of 'cast' here

I'm learning something from programming and I came to this:

While evaluating expressions, the result is automatically updated to larger data type  of the operand. But if we store that result in any smaller data type it generates compile time error, due to which we need to type cast the result.

How to explain cast in the end of the paragraph?
In this context, I would go as throw something away, but yet I don't get it

A:

'type cast' is a single idea.
It's a coding/programming term meaning to specify a data type by forcing it, type-casting it - into the desired form.  
For instance "3" is a 'string', which is a text data type. The quotes in programming make that quite specific; it's not a number any more, it's a string, even though the string contains what to a human looks exactly like a number. Computers don't see things the way humans do.
So - if we need to take that string & force it to become a number, we type-cast it to an integer [which is a whole number with no decimals]
Our string "3" then becomes the integer 3
in pseudo-code...
string myText = "3";
integer myNumber = (integer)myText;
That (integer) in brackets is the 'forcing', the type-cast.
Whether to hyphenate or not is probably a UK/US thing. I'm British, we hyphenate a lot more than the Americans.
I guess it could come from 'to throw' it into a particular type, but I'm not certain. To cast a spell would be a similar use - whether that's 'thrown' might be debatable.
Looking down the 10 meanings in the Oxford Dictionary for 'cast' I honestly wouldn't really know which it would fall under.
It might even be more akin to casting an object from molten metal.

A:

Tetsujin explains the meaning in computer usage. I'd like to try to explain the etymology you're looking for. 
In manufacturing, if a liquid is poured into a mold and allowed to harden into a solid that is determined by the mold, it is said to be "cast in that mold". Type casting is a method of taking a variable and changing its form to a new type or taking an object of unknown type and treating it as a specific type. Just like the liquid in the manufacturing process, it is "cast into the mold" of the type and takes on that form.

