Implicit Type Conversion - C Data Type

C examples for Data Type:Type Cast

Introduction

Type conversions can be classified into two categories.

  • Implicit or automatic type conversion
  • Explicit type conversion

Here is one more example of implicit type conversion (assume counter to be the int variable):

Demo Code

#include <stdio.h>

int main()/*from w w  w .  j a  va 2 s  .  c o m*/
{
    int counter = 14.85;                   /* L3, OK, now value of counter is 14 */
    printf("%d", counter);

    return 0;
}

Result

Here is one more example of implicit type conversion:

Demo Code

#include <stdio.h>

int main()// w  w  w . j av a  2 s.co  m
{
    double d = 2/4.0;                   /* L4, OK, now value of d is 0.500000 */
    printf("%f", d);

    return 0;
}

Result


Related Tutorials