Chapter 11
Advanced Topics
Congratulations! By now you've mastered most of the fundamental C programming concepts. This chapter will fill you in on some useful C programming tips, tricks, and techniques that will enhance your programming skills. We'll start with a look at typecasting, C's mechanism for translating one data type to another.
Typecasting
Often, you will find yourself trying to convert a variable of one type to a variable of another type. For example, this code fragment:
float f;
int i;
f = 3.5;
i = f;
printf( "i is equal to %d", i );
causes the following line to appear in the console window:
i is equal to 3
Notice that the original value assigned to f
was truncated from 3.5 to 3 when the value in f
was assigned to i
. This truncation ...
Get Learn C on the Mac now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.