Chapter 6: C Functions and Program Structures
else getboinked();
ain() function.
n unsigned char:
nsigned char ad1, unsigned char a1)
r = a1 + a2;
nd in ain w r so it gets set to the data returned by
nt main()
add1,add2);
if(results == 2) getrewardd();
}
If you think 1 + 1 = 2 prepare to get boinked. You’ll getrewarded() in adder() and
getboinked() in main(). In the adder function, r = 2, but this doesn’t change the
‘results’ in the parameter list in the function call to adder in the m
Returns
Ouch! Boinking hurts, so Let’s make adder work right, we change the return type
from void to char and declare r as a
char adder(u
{
unsigned char r;
if(r == 2) getrewarded();
else getboinked();
return r;
}
A m e set ‘results’ equal to adde
adder:
i
{
unsigned char add1 = 1;
unsigned char add2 = 1;
unsigned char results = 0;
results = adder(
if(results == 2) getrewarded();
else getboinked();
}
Now we get two rewards. If we want to skip the reward we could write adder: