C examples for Data Type:Type Cast
You can perform the type conversion explicitly.
The operator used in casting is called cast.
#include <stdio.h> int main()/*www. ja v a 2 s. c o m*/ { int counter = (int)14.85; /* L1, OK, casting operation performed */ printf("%d", counter); return 0; }
The generic syntax of a casting operation or explicit type conversion:
(desiredType)expression
#include <stdio.h> int main()//from w w w .j a v a2s . c o m { int counter; double d = 3.7; counter = (int)d; printf("Value of counter is: %d\n", counter); printf("Value of d is: %lf\n", d); printf("Value of d with cast (int) is: %d\n", (int)d); return 0; }