0% found this document useful (0 votes)
7 views

Chapter 6 Function

Chapter 6 discusses functions in programming, defining them as self-contained blocks of statements that perform specific tasks. It categorizes functions based on return types and argument lists, and explains different types of function calls, including call by value and call by reference. Additionally, it covers recursive functions and storage classes in C, detailing local, global, static, and register variables.

Uploaded by

bipinpata2055
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Chapter 6 Function

Chapter 6 discusses functions in programming, defining them as self-contained blocks of statements that perform specific tasks. It categorizes functions based on return types and argument lists, and explains different types of function calls, including call by value and call by reference. Additionally, it covers recursive functions and storage classes in C, detailing local, global, static, and register variables.

Uploaded by

bipinpata2055
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter-6: Function

Function:
A function is defined as a self contained block of
statements that perform a particular task or job.
Syntax:
return_type function_name (argument _list)
{
body of function;
}
category of function on the basis of return type and
argument list
1) no return type no argument list
2) no return type but with argument list
3) return type but no argument list
4) return type with argument list

1) no return type no argument list


Output:

2) no return type but with argument list


Output:

3) return type but no argument list

Output:

4) return type with argument list


Output:

Different types of function call:


There are two types of function call they are as
follows:
1) call by value:
When values of actual arguments are passed to
the function as arguments, it is known as
function call by value.
Output:

2) call by reference:
The address of variable or argument is passed to
the function as argument is known as call by
reference.

Output:
Recursive function:
A recursive function is a function which calls
itself is known as recursive function.
To solve a problem using recursive method, two
conditions must be satisfied. They are:
1) Problem could be written or defined in terms
of its previous result.
2) Problem statement must include a stopping
condition.

q) Write a program to find factorial of a


number using recursive function.
Output:

q) Write a program to find the sum of n


natural number using recursive function.

Output:

Q) Write a program to find the sum of digit of a


number using recursive function.
Output:

q) Write a program to generate Fibonacci series


using recursive function.
Output:

Q) Write a recursive program to raise x to power


n i.e. xn .
Output:
Storage classes in c:
Storage Classes are used to describe the features of a
variable/function. These features basically include the
scope, visibility and life-time which help us to trace the
existence of a particular variable during the runtime of a
program.
In c programming there are 4 types of storage classes.
They are as follows.

1) local variables(automatic variable or internal variable):


 The automatic variables are always declared within
a function or block and are local to the particular
function or block in which they are declared.
 The initial value is un-predictable or garbage value.
 The scope is only within the function or block in
which they are defined.
 A variable declared inside a function without
storage class specification auto is , by default, an
automatic variable.
Output:

2) Global variables(External):
 Global variables are defined outside the function
so that their scope is throughout the program.
 The initial value is Zero.
Output:

3) static variables:
 Static variables are special case of local variables.
 The keyword static is used to declare static
variable.
 The initial value is zero.
Output:

4) register variables:
The register storage class is used to define local
variables that should be stored in a register instead
of RAM.
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy