Course Code: MCT321 Course: Computer Applications L: 3 HRS., T: 1 HRS., Per Week Total Credits: 07
Course Code: MCT321 Course: Computer Applications L: 3 HRS., T: 1 HRS., Per Week Total Credits: 07
Function in C
• A function is a block of code that performs a
particular task.
• C language provides an approach in which you
can declare and define a group of statements
once in the form of a function and it can be
called and used whenever required.
• C functions can be classified into two categories,
– Library functions
– User-defined functions
Unit - I
A User-defined functions
on the other hand, are
those functions which
are defined by the user
at the time of writing
program.
returntype
• When a function is declared to perform some sort of
calculation or any operation and is expected to
provide with some result at the end, in such cases, a
return statement is added at the end of function body.
• Return type specifies the type of value (int, float, char,
double) that function is expected to return to the
program which called the function.
functionName
• Function name is an identifier and it specifies
the name of the function.
• The function name is any valid C identifier and
therefore must follow the same naming rules
like other variables in C language.
Unit - I
parameter list
• The parameter list declares the type and
number of arguments that the function expects
when it is called.
• The parameters in the parameter list receives
the argument values when the function is
called. They are often referred as formal
parameters.
Unit - I
Example
Unit - I
functionbody
• The function body contains the declarations and the
statements(algorithm) necessary for performing the
required task.
• The body is enclosed within curly braces { ... } and
consists of three parts.
– local variable declaration(if required).