From the course: C Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Typecasting a variable

Typecasting a variable - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Typecasting a variable

- [Teacher] This code divides two values which I have assigned to variables a and b, both are integers. The printf statement of line 10 contains the math, a divided by b, the placeholder for the resulting value is percentage d, which outputs a integer value in decimal, build and run. On the code runs, and it works. But the result is shown as 14, which is incorrect. But, this is actually what you directed the program to do, to divide integers. I'm going to change the final placeholder here from percent d to percent f, this output a floating point or real number, is this going to work? I don't know. Let's say this is the fun thing about c, you can always try things out and see how they work. All right, let's just build and see what happens. So we build, surprisingly, there are no errors. You may see a warning which isn't good, but a program is created with a warning, so run it. (laughing) And now the result is…

Contents