what is meant by Type casting?

Explain your own answer with proper example?

  • Rahul
  • 12 Jul
  • 14185 Views
  • 42 Answers
Your Answer

Type casting is a way to convert a variable from one data type to another data type.In simple terms type casting is conversion of variables into different datatypes.
Considering the following example:
#include <stdio.h>
 int main ()
{
    float x;
    x = (float) 7/5;
    printf(“%f”,x);
     }
In the given C program, 7/5 alone will produce integer value as 1.
So, type cast is done before division to retain float value (1.4).

C Language

Didn't get the answer.
Contact people of Talent-C Language directly by clicking here