6 - Elements of Programming Part 4
6 - Elements of Programming Part 4
PROGRAMMING
Part 4
To explain modular programming,
To enumerate other built-in
functions,
And to create functions
Programs in the real world can
be extremely large.
FUNCTIONS
for Modular Programming
FUNCTIONS
aka subroutines
FUNCTIONS
aka procedures
FUNCTIONS
aka modules
We divide this into small
manageable parts
(and one each performs a task).
A large program typically has many
other functions which are
invoked/called by main() or other
functions.
Predefined functions in C
Example: Generating random
numbers
Defining functions in C
Example #1
How does this work?
If a function is called,
execution is transferred
to that function.
That function then
executes its code.
Once the function finishes
or meets a return statement,
control is transferred back.
Example #2
Return now actually returns
something (sum).
c = addUp(a, b);