"casting" is converting one data type into another.
in your example, you declared an object of type "double" named "answr" and then you want to put a result of 2 / 4.
Now, both "2" and "4" are integers and hence the computer decided that both are integers and hence a result should also be of type integer and hence "2 / 4" produced "0" since integer numbers do not have a decimal part and that part is ignored. The resulting number is then assigned to your variable and that is why the result was "0"
doing (double) 2 / 4 forced the calculation to be of type double and that is why it worked because the result will then be "0.5" and then "answr" will be assigned "0.5"
your code would have worked if you had any following combination (2.0 / 4), (2 / 4.0), (2.0 / 4.0). These numbers would have forced the compiler to see your numbers as not integers and a proper calculation and assignment would have taken place.
basically, your numbers made the computer assume you were doing an integer calculation and it went all the way with integers and that is why an explicit cast was required to force the computer to do the calculation with double data type in mind.