Cast one type to another type - C Data Type

C examples for Data Type:Type Cast

Introduction

The following code shows how to cast int to float type.

Demo Code

#include <stdio.h>

int main(void) /* print i and i/2 with fractions */
{
   int i;//from   w w  w .  ja v a  2 s  .com

   for (i = 1; i <= 100; ++i)
      printf("%d / 2 is: %f\n", i, (float)i / 2);
   return 0;

}

Result


Related Tutorials