Program to Demonstrate Typecasting in C
Here is a program to demonstrate typecasting in C programming language. #include #include void main(){ float result; int num1, num2; clrscr(); num1 = 10; num2 = 3; result = num1/num2; printf(“\nBefore Typecasting: %f”,result); /* As num1 and num2 are declared as int, it will return int value and it will get stored in the variable “result” as float i.e. 3.000000 To solve this problem we can use typecasting. */ result = (float)num1/num2; printf(“\nAfter Typecasting: %f”,result); getch(); } Output: Before Typecasting: 3.000000 After Typecasting: 3.333333