A cast takes the form of an abstract type within a pair of parenthesis. An abstract type is same as a declaration but without an identifier (and of course without an initialization). For example: (int *).
What a cast does, is convert the value of the expression to its right (taking into account its relative precedence) to the type in the cast - if that is possible. One can cast a variable or expression of type "double" to "int", but cannot cast an expression of type "int" to a structure or union of any kind as this is not possible. One use of casts is to cast a pointer to "void" to a pointer of some other type so that the pointer can now be used. But, one must be sure that the original and cast pointer have the same length.
In the following program fragment:
double x; x=9/5;
If in this case one expected 'x' to be 1.8, it would not. Since both '' and '5' are integers the division would be integer and the result would be '1'. If the entire expression was cast as follows:
x=(double)(9/5);
the result would still be 1.0 because the cast is applied to the result of the integer division. One would have to do the following to get 1.8:
x=((double)9)/5;
In this particular case a cast was not truly necessary as one could have written;
x=9./5;
But when the numbers being divided are variables rather than constants then the casts become unavoidable to get the fractional value.