Comp Sci: what is casting?

Tutoring comp sci, casting will come up: the tutor defines it.

Casting, in computer science, means changing a variable’s type to a different one. Typically, the result will be stored in a new variable.

An example where casting might be needed is as follows: Receiving user input, it’s usually thought of as a string. Yet, what if it’s meant to be a decimal number? (You can’t predictably add strings.)

If x is the input, then typically you’ll see something like y=(float)x; then, y will contain the float (in simple terms, decimal) representation of the number that was entered. This operation is typically called casting or a cast.


Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply