Functions: What Is A Function?
Functions: What Is A Function?
What is a function?
and gives it a name. This can then be invoked from other parts of
the program.
code.
to 300.
statements }
from the next by a comma. Each parameter looks very much like a
regular variable declaration (for example: int x), and in fact acts
does.
Time to try?
Declaration
Definition
Invoking
There are two sorted arrays. First one is of size m+n containing
Write a function to merge these two arrays into the first array of
size m+n.
Home Work
Write a function which takes a number X and a array and prints all
Write a function which takes two sorted arrays, and their lengths as
third array.
name and define the function before any calls are made to the
function
The compiler can ignore the inline qualifier in case defined function
Default Parameter
If the user does not supply a value for this parameter, the default
value will be used. If the user does supply a value for the default
destroyed
Local Variables
Variables defined inside a block are called
local variables.
created when the block they are part of is entered, and destroyed
Local variables have block scope (also called local scope), which
means they are visible only within the block that they are defined
in.
Global Variables
Global variables have static duration, which means they are created
scope†), which means they are visible until the end of the file in
that retains its value even after the scope in which it has been
created has been exited!
and then they are persisted throughout the life of the program.
Function Overloading
You can have multiple definitions for the same function name in the
same scope
The definition of the function must differ from each other by the
You can not overload function declarations that differ only by return
type.