LAB 6
–
To learn the use of functions
–
To get familiar with parameter passing
Functions allow to assemble programs in segments of code to perform individual tasks. They let you
chop up a long program into named sections so that the sections can be reused throughout the
program.
In this lab you are going to learn how to define your own functions to perform any task you want. These
are called user defined functions. While designing, this is always a good approach to make your
function appear as black box. Function has a name identifier, accepts parameters and returns a result.
Example:
auto function_name (parameter_list)
{
…code…
return result_of_function
}
Definition:
Definition of a function is actually the function itself. It consists of a line called declarator or head
followed by the statements in braces.
Function Call:
To call a function in main() you need to write function name followed by parenthesis. After seeing