Chapter 6: C Functions and Program Structures...................................................
m
u are probably wondering why you bought the Butterfly and all that
nd define some things. First a ‘reuse’
f what was said earlier:
ing and provides the possibility of
as important, it provides a way
rogrammer to mess with it
so important in software
+ language was developed primarily to formalize these
e calls to the function.
A function definition is the function text as:
void sendChar(char myData)
Chapter 6: C Functions and Progra
Structures
Function Basics
About now yo
cool hardware. Where are the projects? Let’s blow something up! Patience
grasshopper, we’ll have a project at the end of this chapter and many more later. It
will be worth it, I promise.
We’ve been using functions enough that by now you probably have a good
intuitive feel for them, but Let’s be formal a
o
Encapsulation is a key idea in C programm
making chunks of code convenient to use. And just
to make tested code reusable while not allowing the p
and chance breaking something. These ideas are
engineering that the C+
concepts and force their use.
One of the main functions of functions (har!) is to break computations up into
logical chunks and separate them to help clarify the code. If you find yourself
writing a function that seems to be doing two separable things, try separating it
into two functions.
A function must be declared before it is defined somewhere, usually in a header
file or before the main() function. For example:
void sendChar(char ) ;
Which tells the compiler that the sendChar() function takes a char as an argument
and doesn’t return anything when finished. The compiler can use this information
to make sure you are using it correctly when you mak