Sams Teach Yourself C in 21 Days

(singke) #1

DAY 20


WEEK 3


Working with Memory


Today’s lesson covers some of the more advanced aspects of managing memory
within your C programs. Today you will learn


  • About type conversions

  • How to allocate and free memory storage

  • How to manipulate memory blocks

  • How to manipulate individual bits


Type Conversions ................................................................................................


All of C’s data objects have a specific type. A numeric variable can be an int
or a float, a pointer can be a pointer to a doubleorchar, and so on. Programs
often require that different types be combined in expressions and statements.
What happens in such cases? Sometimes C automatically handles the different
types, so you don’t need to be concerned. Other times, you must explicitly con-
vert one data type to another to avoid erroneous results. You’ve seen this on ear-
lier days’ lessons when you had to convert or cast a type voidpointer to a
specific type before using it. In this and other situations, you need a clear
understanding of when explicit type conversions are necessary and what types

32 448201x-CH20 8/13/02 11:16 AM Page 565

Free download pdf