[C] Casting
#include <stdio.h>
int main(void)
{
int a = 35;
int b = 45.78;
puts("----------------------------");
puts(" * Casting * ");
puts("----------------------------");
printf(" a = %d, b = %d \n", a, b);
puts("----------------------------");
puts(" 45.78 data type becomes to int type");
puts("----------------------------");
return 0;
/*
----------------------------
* Casting *
----------------------------
a = 35, b = 45
----------------------------
45.78 data type becomes to int type
----------------------------
*/
}
#include <stdio.h>
int main(void)
{
double a = 35.678;
double b = 45;
puts("------------------------");
puts(" Casting - double ");
puts("------------------------");
printf(" a = %lf, b = %lf \n", a, b);
printf(" a = %.1lf, b = %.2lf \n", a, b);
puts("------------------------");
puts(" 45 becomes double ");
return 0;
/*
------------------------
Casting - double
------------------------
a = 35.678000, b = 45.000000
a = 35.7, b = 45.00
------------------------
45 becomes double
*/
}
#include <stdio.h>
int main(void)
{
int a = (int)35.678;
float b = 55.545;
float c = 55.545f;
puts("--------------------------");
puts(" Casting ");
puts("--------------------------");
printf(" a = %d, b = %2.f, c = %.2f \n", a, b, c);
puts("--------------------------");
return 0;
/*
--------------------------
Casting
--------------------------
a = 35, b = 56, c = 55.54
--------------------------
*/
}