/* * programming_casting.c * * Created on: Sep 27, 2023 * Author: johnsontimoj */ //////////////////////////////////// // // Program to show type casting concepts // // inputs: user // outputs: prints // ////////////////////////////////// #include int main(void){ setbuf(stdout, NULL); // splash printf("----------------------------\n"); printf(" practice with type casts\n"); printf("----------------------------\n\n"); // declare some variables int a; int b; float c; float d; char e; char f; // start an infinite loop (on faith for now) while(1){ // get some values printf("Please enter 2 ints, 2 floats, and 2 chars: "); scanf("%i %i %f %f %c %c", &a, &b, &c, &d, &e, &f); // assignment type casting c = a + b; printf("c is: %f\n", c); a = 2 * d; printf("a is: %i\n", a); c = e; printf("c is: %f\n", c); // explicit type casting c = (int)d; printf("c is: %f\n", c); printf("d is: %f\n", d); // note d was not changed in the type cast c = (float)(a/b); printf("c is: %f\n", c); c = a/(float)b; printf("c is: %f\n", c); c = (float)a/b; printf("c is: %f\n", c); // implicit type conversion c = a * d + a % b; printf("c is: %f\n", c); printf("\n\n"); }// end while return 0; }// end main