A typecast ensures that whatever data type is used matches the data type required, for example, so that an integer value is treated as a floating-point value to ensure a proper calculation. A typecast allows for flexibility in your code, allowing one data type to act like another when needed to properly formulate an expression.
- [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 really wrong. … To truly get the decimal result …
- Writing your first C program
- Working the C development cycle
- Adding comments to code for clarity
- C language data types
- Declaring variables
- Making new data types
- Typecasting variables
- Using math, assignment, and logical operators
- Creating for and while loops
- Nesting loops
- Creating functions
- Returning values from functions
- Passing arguments to functions
- Creating recursive functions
Skill Level Intermediate
C: Data Structures, Pointers, and File Systemswith Dan Gookin2h 57m Intermediate
1. The Fundamentals of C
2. Variables and Values
3. Operators and Math
4. Decisions and Loops
Next steps1m 38s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.