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 - C Tutorial
From the course: C Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understanding C language data types3m 4s
-
(Locked)
Declaring variables2m 49s
-
(Locked)
Working with variables2m 55s
-
(Locked)
Exploring the printf() function3m 4s
-
(Locked)
Using constants2m 53s
-
(Locked)
Challenge: Make variables and constants47s
-
Solution: Make variables and constants1m
-
(Locked)
Understanding variable scope3m 8s
-
(Locked)
Making new data types3m 24s
-
(Locked)
Specifying characters and strings3m 17s
-
(Locked)
Specifying integers and real numbers4m 14s
-
(Locked)
Typecasting a variable3m 11s
-
(Locked)
Challenge: Basic I/O1m 10s
-
(Locked)
Solution: Basic I/O1m 35s
-
-
-
-
-