SlideShare a Scribd company logo
MANSI TYAGI
FUNCTION
De_nition
 A’C’ program consists of one or more functions.
 Every program must contain atleast one function named as main( ),
where the program always begins execution.
 Functions are normally used to divide a large program into smaller
programs which are easier to handle.
 Function after its execution returns a single value.
Need of Functions :of Function
Several advantages of modularizing a program into function includes:
 Reduction in code redundancy
 Enabling code reuse
 Better readability
 Information Hiding
 Improved debugging and testing
 Improved maintainability
Abhineet
A function is a self contained block of codes or sub programs with a set of
statements that perform some specific task or coherent task.
MANSI TYAGI
There are basically two types of function those are:
1. Library function
2. User defined function
1. Library /Built in /Standard function :
These functions that are inbuilt in the C language compiler are library
functions i.e: printf() and scanf() belongs to the category of library
functions.
 These functions are present in C library and they are
predefined.
For ex: printf(),scanf(),getch(),clrscr(),main().
2. User defined function :
These functions that are defined by the user according to its requirement
at the time of writing the program.
 User can create their own functions for performing any
specific task of the program.These types of functions are
called user-defined functions.
 There are three aspect of working with user-defined
functions:
1. Function Declaration, also known as function prototype
2. Function Definition
3. Function Call or function invocation
MANSI TYAGI
Syntax:-
Return type function name (argument list )
Return type name of function (type 1 arg 1, type2 arg2, type3 arg3)
 So when user gets his own function three thing he has to know, these
are.
Function declaration
Function definition
Function call
These three things are represented like :
int function(int, int, int); /*function declaration*/
main()
{
function(arg1,arg2,arg3); /* calling function*/
}
int function(type 1 arg 1,type2 arg2,type3, arg3) /*function definition/*
{
Local variable declaration;
Statement;
Return value;
}
 Function declaration:-
Function declaration is also known as function prototype. It inform the compiler
about three thing, those are name of the function, and type of argument
received by the function and the type of value returned by the function.
 Function prototype always terminated by the semicolon.
Syntax:
Type function_name(parameter list);
int function(int, int, int); /*function declaration*
Ex- int add(int x,int y);
MANSI TYAGI
 Function definition:-
Function definition consists of the whole description and code of the function.
It tells about what function is doing what are its inputs and what are its out put
It consists of two parts function header and function body.
Syntax:-
return type function(type 1 arg1, type2 arg2, type3 arg3) /*function header*/
{
Local variable declaration;
Statement 1;
Statement 2; /*function body*/
Return value;
}
 The local variable declared inside a function is local to that function only. It
can’t be used anywhere in the program and its existence is only within this
function.
 The arguments of the function definition are known as formal arguments.
 Function Call :
When the function get called by the calling function then that is called, function
call. The compiler execute these functions when the semicolon is followed by the
function name.
Example:-
function(arg1,arg2,arg3);
The argument that are used inside the function call are called actual argument
Ex:-
int S=sum(a, b); //actual arguments
MANSI TYAGI
PARAMETER PASSING:
Parameters are nothing but input information given to a function. By passing
parameters the caller can ask the function to process a set of values. Parameter passing
allows you to run generalized and reusable functions.
 What ever the parameters the caller passes are called the actual parameters and
 what ever parameters the function is return to receive are called the formal
parameters.
 The actual parameters are copied to the formal parameters.
The arguments which are mentioned or used inside the function call is knows as
actual argument and these are the original values and copy of these are actually
sent to the called function.
 The actual parameters are copied to the formal parameters.
It can be written as constant, expression or any function call like
Function (x);
Function (20, 30);
Example
Main()
{
Int ans;
Ans=add(a,b);
Actual argument
1. Actual Argument
1. Actual Argument
MANSI TYAGI
The arguments which are mentioned in function definition are called formal
arguments or dummy arguments.These arguments are used to just hold the copied
of the values that are sent by the calling function through the function call.
Example:
Int add (int x, int y) //*function definition*//
Formal Parameter/Argument
SCOPE OF VARIABLES
Scope of a variable means the portion of the program within which it can be
referenced and lifetime means the time of its existence in the memory.
The scope of local variables is limited to the functions in which they are declared,
or in other words these variables are inaccessible outside of the function. Like
wise the scope of the block variables is limited to the block in which they are
declared. Global have a scope that spans the entire source program, which is why
they can be used in any function.
1>.Local Variable 2>.Global Variable
1. LOCAL VARIABLES: Local variables that are defined with in a body of
function or block. The local variables can be used only in that function or block in
which they are declared.
Example : function()
{
int a,b;
2. Formal Argument
MANSI TYAGI
function 1();
}
2.GLOBAL VARIABLES :
These variables that are defined outside of the function is called global
variable/External variables. All functions in the program can access and modify
global variables.
 A global variable can be used any where in the program.
 Global variables are automatically initialized at the time of initialization.
Example:
#include<stdio.h>
void function(void);
void function1(void);
void function2(void);
int a, b=20; // * global variables *//
void main()
{
printf(“inside main a=%d,b=%d n”,a,b);
function();
function1();
function2();
}
function()
{
Prinf(“inside function a=%d,b=%dn”,a,b);
}
function 1()
{
GLOBAL vs LOCAL VARIABLES:
1. Local variables can be used only inside the function of the block in which they are
declared. On the other hand global variables are used through out the program.
MANSI TYAGI
2. All global variables, in the absence of explicit initialization, are automatically
initialized to zero. On the other hand All local variables, in the absence of explicit
initialization, are automatically initialized to garbage value.
3. The initial that you supplied for a global variable must be a constant, where as a
local variable can contain variable in its initializer.
4. A local variables loses its value the movement the function/block containing it is
exited. So you cannot expect a local variable to retain the value deposited in it the
previous time the function/block was entered. Global variables retain there values
through the program’s execution.
i) Function with no argument & no return value
Function that have no argument and no return value is written as:-
SYNTAX :
void function(void);
main()
{
void function()
{
Statement;
}
Category of Function based on argument and return type
i) Function with no argument & no return value
ii) Function with no argument but return value
iii ) function with argument but no return value
iv) function with argument and return value
MANSI TYAGI
Example :
#include<stdio.h>
#include<conio.h>
Void add (void);
{ Main()
Add();
}
Void add (void)
{
Int a,b,c;
Printf(“enter two valu”);
Scanf(“%d%d”,&a,&b);
C=a+b;
Printf(“%d”,c);
}
ii) Function with no argument but return value
Syntax:-
int fun(void);
main()
MANSI TYAGI
{
int r;
r=fun();
}
int fun()
{
reurn(exp);
}
Example:-
int sum();
main()
{
int b=sum();
printf(“entered %dn, b”);
}
int sum()
{
int a,b,s;
s=a+b;
return s;
}
Here called function is independent and are initialized. The values aren’t
passed by the calling function .Here the calling function and called function are
communicated partly with each other.
iii ) function with argument but no return value
Here the function have argument so the calling function send data to the called
function but called function does not return value.
MANSI TYAGI
Syntax:-
void fun (int,int);
main()
{
int (a,b);
}
void fun(int x, int y);
{
Statement;
}
Here the result obtained by the called function.
iv) function with argument and return value
Here the calling function has the argument to pass to the called function and the
called function returned value to the calling function.
Syntax:-
fun(int,int);
main()
{
int r=fun(a,b);
}
int fun(intx,inty)
{
return(exp);
}
 Example:
main()
{
int fun(int);
int a,num;
printf(“enter value:n”);
scanf(“%d”,&a)
int num=fun(a);
}
int fun(int x)
{
++x;
MANSI TYAGI
return x;
}
Call by value and call by reference
There are two way through which we can pass the arguments to the
function such as call by value and call by reference.
1. Call by value
In the call by value copy of the actual argument is passed to the
formal argument and the operation is done on formal argument.When
the function is called by ‘call by value’ method.
 It does not affect content of the actual argument. Changes made
to formal argument are local to block of called function so when
the control back to calling function the changes made is vanish.
 Example:-
main()
{
int x,y;
change(int,int);
printf(“enter two values:n”);
scanf(“%d%d”,&x,&y);
MANSI TYAGI
change(x ,y);
printf(“value of x=%d and y=%dn”,x ,y);
}
change(int a,int b);
{
int k;
k=a;
a=b;
b=k;
}
Output: enter two values: 12 ,23
Value of x=12 and y=23
2. Call by reference
Instead of passing the value of variable, address or reference is
passed and the function operate on address of the variable rather than
value.
 Here formal argument is alter to the actual argument, it
means formal arguments calls the actual arguments.
 Example:-
void main()
{
int a,b;
MANSI TYAGI
change(int *,int*);
printf(“enter two values:n”);
scanf(“%d%d”,&a,&b);
change(&a,&b);
printf(“after changing two value of a=%d and b=%dn:”a,b);
}
change(int *a, int *b)
{
int k;
k=*a;
*a=*b;
*b= k;
printf(“value in this function a=%d and b=%dn”,*a,*b);
}
Output: enter two values: 12, 32
Value in this function a=32 and b=12
After changing two value of a=32 and b=12
 So here instead of passing value of the variable, directly
passing address of the variables. Formal argument directly
access the value and swapping is possible even after calling a
function.
MANSI TYAGI
STORAGE CLASSES:
The storage class in C provides the complete information about the location and
visibility of variables.
 To define a variable in C one needs to mention not only its but also its
storage class. In other words , not only do all variables have a data type,
they also have a storage class.
 If we do not specify the storage class of a variable in its declaration , the
compiler will resume a storage class dependent on the context in which the
variable is used. Thus C has got certain default storage classes.
 Moreover, a variables storage class tells us:
 Where the variable would be stored.
 What will be the initial value of the variable , if the initial value is not
specifically assigned( i.e. the default initial value)
 What is the scope of the variable i.e in which function the value of
the variable would be available.
 What is the life of the variable, i.e. how long would the variable exist.
TYPES OF STORAGE CLASSES:
a) Automatic storage class.
b) Register storage class.
c) Static storage class.
d) External storage class.
MANSI TYAGI
1. AUTOMATIC VARIABLES: Automatic variables are declared
inside a function in which they are used they are to be utilized.
They are created when the function is called and destroyed
automatically when they are declared. Because of this property,
automatic variables are also referred to as local or internal
variables.
Syntax :
We may also use the key word auto to declare automatic variables.
main()
{
auto int n;
Statements;
}
FEATURES OF AUTOMATIC
1.Storage : Memory
2.Default initial value : A garbage value
3.Scope: Local to the block in which it is declared.
4.Life: As long as the program control remains
within the block in which it is declared.
MANSI TYAGI
2.REGISTERS STORAGE CLASSES :
We can tell the compiler that a variable should be kept in one of the machine’s
register, instead of keeping in the memory. Since a register access is much faster
than a memory access. Keeping the frequently accessed variables in the register
will lead to faster execution of programs.
Syntax :
register int i;
3.STATIC STORAGE CLASS:
As the name suggests, the value of static variables persists until the end of the
program. A variable can be declared static using the keyword static.
A static variables may be either an internal type or an external type, depending on
the place of declaration.
main()
{
int i;
FEATURES OF REGISTERS
1.Storage : Memory
2.Default initial value : A garbage value
3.Scope: Local to the block in which it is declared.
4.Life: As long as the program control remains
within the block in which it is declared.
MANSI TYAGI
for(i=1;i<=3;i++)
fun();
}
fun()
{
static int x=5;
x=x+3;
printf(“x=%dn”, x);
}
4.EXTERNAL STORAGE CLASS:
Variables that are both alive and active throughout the entire program are known as
external variables. They are also known as global variables. External variables are
declared outside a function.
FEATURES OF STATIC
1.Storage : Memory
2.Default initial value : ZERO
3.Scope: Local to the block in which it is declared.
4.Life:Variables retains its value betwwn different
functions calls.
FEATURES OF STATIC
1.Storage : Memory
2.Default initial value : ZERO
3.Scope: In all functions of a program i.e: global
4.Life: Throughout the program execution.
MANSI TYAGI
Recursion
The function called by itself (inside function body) is called
recursive function and this process often referred as
recursion.
 In recursion calling function and called function are same.
 It is powerful technique of writing complicated algorithm in easiest way.
 According to recursion problem is defined in term of itself. Here statement
with in body of the function calls the same function and same times it is
called as circular definition.
 In other words recursion is the process of defining something in form of
itself.
Important conditions: There are two important conditions that must be satisfied
by any recursive procedure.
1.Each time a procedure calls itself, it must be nearer to a solution.
2.There must be a decision criterion for stopping the computation.
Types of recursion:
There are two types of recursions.
1.The first type concerns recursively defined functions. Example of this
kind is the Factorial function.
2.The second type of recursion is the recursive use of a procedure.
Syntax:
main ()
{
rec(); /*function call*/
rec();
rec();
MANSI TYAGI
Ex:- /*calculate factorial of a no.using recursion*/
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int num;
printf(“enter a number”);
scanf(“%d”,&num);
f=fact(num);
printf(“factorial is =%dn”f);
}
fact (int num)
{
If (num==0||num==1)
return 1;
else
return(num*fact(num-1));
}
MANSI TYAGI
IMPORTANT QUESTIONS
Q1. What is user defined functions?what is recursion?what are the
conditions for recursion to be convergent?write a recursive function to
compute factorial of a given number?Make use of this function to
compute the value of NCr.
Q2.Distinguish between Call by value and Call by reference methods of
parameter passings by giving suitable example?
Q3.Explain the concept of Storage classes.Explain eaxh with an
example.
Q4.Explain the concept of variables?
Q5.What is Recursion? Explain with its suitable example.
Q6. What do you understand by functions?Explain with its types.
Q7. What is user defined functions?How can you return a value from a
function?Explain with an example .Also discuss different methods to
pass parameters to a function by giving suitable examples.
Ad

More Related Content

What's hot (20)

Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Harsh Pathak
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
Abu Bakr Ramadan
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Functions in C
Functions in CFunctions in C
Functions in C
Shobhit Upadhyay
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
OOP Programs
OOP ProgramsOOP Programs
OOP Programs
hirrahAzhar
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
Haresh Jaiswal
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
BoomBoomers
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
bhawna kol
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
Sachin Sharma
 
C function presentation
C function presentationC function presentation
C function presentation
Touhidul Shawan
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Harsh Pathak
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
Haresh Jaiswal
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
BoomBoomers
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
bhawna kol
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 

Similar to FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) (20)

Functions
Functions Functions
Functions
Dr.Subha Krishna
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
Praveen M Jigajinni
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
Ahmad Kamal
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
Deepak Singh
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
Hattori Sidek
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
nikshaikh786
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
C functions list
C functions listC functions list
C functions list
Thesis Scientist Private Limited
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
Arpit Meena
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
Muhammad Hammad Waseem
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
4. function
4. function4. function
4. function
Shankar Gangaju
 
Functions in c
Functions in cFunctions in c
Functions in c
SunithaVesalpu
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
Krushal Kakadia
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfytttttttttttttttttttttttttttttAll chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
TeshaleSiyum
 
Ad

More from Mansi Tyagi (20)

Unit 5 INTERNATIONAL THEORY
Unit 5 INTERNATIONAL THEORYUnit 5 INTERNATIONAL THEORY
Unit 5 INTERNATIONAL THEORY
Mansi Tyagi
 
Unit 2 foreign trade topic 2 3 4 5
Unit 2 foreign trade topic 2 3 4 5Unit 2 foreign trade topic 2 3 4 5
Unit 2 foreign trade topic 2 3 4 5
Mansi Tyagi
 
Unit 2 Foreign trade
Unit 2 Foreign tradeUnit 2 Foreign trade
Unit 2 Foreign trade
Mansi Tyagi
 
Unit 1 international trade
Unit 1 international tradeUnit 1 international trade
Unit 1 international trade
Mansi Tyagi
 
Unit 1 international trade theory
Unit 1 international trade theoryUnit 1 international trade theory
Unit 1 international trade theory
Mansi Tyagi
 
Unit 5 Sales Management
Unit 5 Sales ManagementUnit 5 Sales Management
Unit 5 Sales Management
Mansi Tyagi
 
Unit 4 Sales Management
Unit 4 Sales ManagementUnit 4 Sales Management
Unit 4 Sales Management
Mansi Tyagi
 
Unit 3 Sales Management
Unit 3 Sales ManagementUnit 3 Sales Management
Unit 3 Sales Management
Mansi Tyagi
 
Unit 2 Sales Management
Unit 2 Sales ManagementUnit 2 Sales Management
Unit 2 Sales Management
Mansi Tyagi
 
Unit 1 Sales Mgt
Unit  1 Sales Mgt Unit  1 Sales Mgt
Unit 1 Sales Mgt
Mansi Tyagi
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
Mansi Tyagi
 
BONUS ACT (HRM)
BONUS ACT (HRM)BONUS ACT (HRM)
BONUS ACT (HRM)
Mansi Tyagi
 
RESEARCH REPORT
RESEARCH REPORT RESEARCH REPORT
RESEARCH REPORT
Mansi Tyagi
 
A study of employee motivation
A study of employee motivationA study of employee motivation
A study of employee motivation
Mansi Tyagi
 
PROJECT REPORT ON CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL)
PROJECT REPORT ON  CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL) PROJECT REPORT ON  CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL)
PROJECT REPORT ON CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL)
Mansi Tyagi
 
PROJECT ON ANDROID APPLICATION
PROJECT ON ANDROID APPLICATIONPROJECT ON ANDROID APPLICATION
PROJECT ON ANDROID APPLICATION
Mansi Tyagi
 
Role of digital marketing
Role of digital marketingRole of digital marketing
Role of digital marketing
Mansi Tyagi
 
BUSINESS REPORT WRITING
BUSINESS REPORT WRITINGBUSINESS REPORT WRITING
BUSINESS REPORT WRITING
Mansi Tyagi
 
Childhood Asthma
Childhood AsthmaChildhood Asthma
Childhood Asthma
Mansi Tyagi
 
PROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEM
PROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEMPROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEM
PROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEM
Mansi Tyagi
 
Unit 5 INTERNATIONAL THEORY
Unit 5 INTERNATIONAL THEORYUnit 5 INTERNATIONAL THEORY
Unit 5 INTERNATIONAL THEORY
Mansi Tyagi
 
Unit 2 foreign trade topic 2 3 4 5
Unit 2 foreign trade topic 2 3 4 5Unit 2 foreign trade topic 2 3 4 5
Unit 2 foreign trade topic 2 3 4 5
Mansi Tyagi
 
Unit 2 Foreign trade
Unit 2 Foreign tradeUnit 2 Foreign trade
Unit 2 Foreign trade
Mansi Tyagi
 
Unit 1 international trade
Unit 1 international tradeUnit 1 international trade
Unit 1 international trade
Mansi Tyagi
 
Unit 1 international trade theory
Unit 1 international trade theoryUnit 1 international trade theory
Unit 1 international trade theory
Mansi Tyagi
 
Unit 5 Sales Management
Unit 5 Sales ManagementUnit 5 Sales Management
Unit 5 Sales Management
Mansi Tyagi
 
Unit 4 Sales Management
Unit 4 Sales ManagementUnit 4 Sales Management
Unit 4 Sales Management
Mansi Tyagi
 
Unit 3 Sales Management
Unit 3 Sales ManagementUnit 3 Sales Management
Unit 3 Sales Management
Mansi Tyagi
 
Unit 2 Sales Management
Unit 2 Sales ManagementUnit 2 Sales Management
Unit 2 Sales Management
Mansi Tyagi
 
Unit 1 Sales Mgt
Unit  1 Sales Mgt Unit  1 Sales Mgt
Unit 1 Sales Mgt
Mansi Tyagi
 
C Language Programs
C Language Programs C Language Programs
C Language Programs
Mansi Tyagi
 
RESEARCH REPORT
RESEARCH REPORT RESEARCH REPORT
RESEARCH REPORT
Mansi Tyagi
 
A study of employee motivation
A study of employee motivationA study of employee motivation
A study of employee motivation
Mansi Tyagi
 
PROJECT REPORT ON CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL)
PROJECT REPORT ON  CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL) PROJECT REPORT ON  CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL)
PROJECT REPORT ON CONSUMER BUYING BEHAVIOUR IN INDIAN SHOPPING MALL)
Mansi Tyagi
 
PROJECT ON ANDROID APPLICATION
PROJECT ON ANDROID APPLICATIONPROJECT ON ANDROID APPLICATION
PROJECT ON ANDROID APPLICATION
Mansi Tyagi
 
Role of digital marketing
Role of digital marketingRole of digital marketing
Role of digital marketing
Mansi Tyagi
 
BUSINESS REPORT WRITING
BUSINESS REPORT WRITINGBUSINESS REPORT WRITING
BUSINESS REPORT WRITING
Mansi Tyagi
 
Childhood Asthma
Childhood AsthmaChildhood Asthma
Childhood Asthma
Mansi Tyagi
 
PROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEM
PROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEMPROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEM
PROJECT ON EXISTING EMPLOYEE ENGAGEMENT SYSTEM
Mansi Tyagi
 
Ad

Recently uploaded (20)

Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 

FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)

  • 1. MANSI TYAGI FUNCTION De_nition  A’C’ program consists of one or more functions.  Every program must contain atleast one function named as main( ), where the program always begins execution.  Functions are normally used to divide a large program into smaller programs which are easier to handle.  Function after its execution returns a single value. Need of Functions :of Function Several advantages of modularizing a program into function includes:  Reduction in code redundancy  Enabling code reuse  Better readability  Information Hiding  Improved debugging and testing  Improved maintainability Abhineet A function is a self contained block of codes or sub programs with a set of statements that perform some specific task or coherent task.
  • 2. MANSI TYAGI There are basically two types of function those are: 1. Library function 2. User defined function 1. Library /Built in /Standard function : These functions that are inbuilt in the C language compiler are library functions i.e: printf() and scanf() belongs to the category of library functions.  These functions are present in C library and they are predefined. For ex: printf(),scanf(),getch(),clrscr(),main(). 2. User defined function : These functions that are defined by the user according to its requirement at the time of writing the program.  User can create their own functions for performing any specific task of the program.These types of functions are called user-defined functions.  There are three aspect of working with user-defined functions: 1. Function Declaration, also known as function prototype 2. Function Definition 3. Function Call or function invocation
  • 3. MANSI TYAGI Syntax:- Return type function name (argument list ) Return type name of function (type 1 arg 1, type2 arg2, type3 arg3)  So when user gets his own function three thing he has to know, these are. Function declaration Function definition Function call These three things are represented like : int function(int, int, int); /*function declaration*/ main() { function(arg1,arg2,arg3); /* calling function*/ } int function(type 1 arg 1,type2 arg2,type3, arg3) /*function definition/* { Local variable declaration; Statement; Return value; }  Function declaration:- Function declaration is also known as function prototype. It inform the compiler about three thing, those are name of the function, and type of argument received by the function and the type of value returned by the function.  Function prototype always terminated by the semicolon. Syntax: Type function_name(parameter list); int function(int, int, int); /*function declaration* Ex- int add(int x,int y);
  • 4. MANSI TYAGI  Function definition:- Function definition consists of the whole description and code of the function. It tells about what function is doing what are its inputs and what are its out put It consists of two parts function header and function body. Syntax:- return type function(type 1 arg1, type2 arg2, type3 arg3) /*function header*/ { Local variable declaration; Statement 1; Statement 2; /*function body*/ Return value; }  The local variable declared inside a function is local to that function only. It can’t be used anywhere in the program and its existence is only within this function.  The arguments of the function definition are known as formal arguments.  Function Call : When the function get called by the calling function then that is called, function call. The compiler execute these functions when the semicolon is followed by the function name. Example:- function(arg1,arg2,arg3); The argument that are used inside the function call are called actual argument Ex:- int S=sum(a, b); //actual arguments
  • 5. MANSI TYAGI PARAMETER PASSING: Parameters are nothing but input information given to a function. By passing parameters the caller can ask the function to process a set of values. Parameter passing allows you to run generalized and reusable functions.  What ever the parameters the caller passes are called the actual parameters and  what ever parameters the function is return to receive are called the formal parameters.  The actual parameters are copied to the formal parameters. The arguments which are mentioned or used inside the function call is knows as actual argument and these are the original values and copy of these are actually sent to the called function.  The actual parameters are copied to the formal parameters. It can be written as constant, expression or any function call like Function (x); Function (20, 30); Example Main() { Int ans; Ans=add(a,b); Actual argument 1. Actual Argument 1. Actual Argument
  • 6. MANSI TYAGI The arguments which are mentioned in function definition are called formal arguments or dummy arguments.These arguments are used to just hold the copied of the values that are sent by the calling function through the function call. Example: Int add (int x, int y) //*function definition*// Formal Parameter/Argument SCOPE OF VARIABLES Scope of a variable means the portion of the program within which it can be referenced and lifetime means the time of its existence in the memory. The scope of local variables is limited to the functions in which they are declared, or in other words these variables are inaccessible outside of the function. Like wise the scope of the block variables is limited to the block in which they are declared. Global have a scope that spans the entire source program, which is why they can be used in any function. 1>.Local Variable 2>.Global Variable 1. LOCAL VARIABLES: Local variables that are defined with in a body of function or block. The local variables can be used only in that function or block in which they are declared. Example : function() { int a,b; 2. Formal Argument
  • 7. MANSI TYAGI function 1(); } 2.GLOBAL VARIABLES : These variables that are defined outside of the function is called global variable/External variables. All functions in the program can access and modify global variables.  A global variable can be used any where in the program.  Global variables are automatically initialized at the time of initialization. Example: #include<stdio.h> void function(void); void function1(void); void function2(void); int a, b=20; // * global variables *// void main() { printf(“inside main a=%d,b=%d n”,a,b); function(); function1(); function2(); } function() { Prinf(“inside function a=%d,b=%dn”,a,b); } function 1() { GLOBAL vs LOCAL VARIABLES: 1. Local variables can be used only inside the function of the block in which they are declared. On the other hand global variables are used through out the program.
  • 8. MANSI TYAGI 2. All global variables, in the absence of explicit initialization, are automatically initialized to zero. On the other hand All local variables, in the absence of explicit initialization, are automatically initialized to garbage value. 3. The initial that you supplied for a global variable must be a constant, where as a local variable can contain variable in its initializer. 4. A local variables loses its value the movement the function/block containing it is exited. So you cannot expect a local variable to retain the value deposited in it the previous time the function/block was entered. Global variables retain there values through the program’s execution. i) Function with no argument & no return value Function that have no argument and no return value is written as:- SYNTAX : void function(void); main() { void function() { Statement; } Category of Function based on argument and return type i) Function with no argument & no return value ii) Function with no argument but return value iii ) function with argument but no return value iv) function with argument and return value
  • 9. MANSI TYAGI Example : #include<stdio.h> #include<conio.h> Void add (void); { Main() Add(); } Void add (void) { Int a,b,c; Printf(“enter two valu”); Scanf(“%d%d”,&a,&b); C=a+b; Printf(“%d”,c); } ii) Function with no argument but return value Syntax:- int fun(void); main()
  • 10. MANSI TYAGI { int r; r=fun(); } int fun() { reurn(exp); } Example:- int sum(); main() { int b=sum(); printf(“entered %dn, b”); } int sum() { int a,b,s; s=a+b; return s; } Here called function is independent and are initialized. The values aren’t passed by the calling function .Here the calling function and called function are communicated partly with each other. iii ) function with argument but no return value Here the function have argument so the calling function send data to the called function but called function does not return value.
  • 11. MANSI TYAGI Syntax:- void fun (int,int); main() { int (a,b); } void fun(int x, int y); { Statement; } Here the result obtained by the called function. iv) function with argument and return value Here the calling function has the argument to pass to the called function and the called function returned value to the calling function. Syntax:- fun(int,int); main() { int r=fun(a,b); } int fun(intx,inty) { return(exp); }  Example: main() { int fun(int); int a,num; printf(“enter value:n”); scanf(“%d”,&a) int num=fun(a); } int fun(int x) { ++x;
  • 12. MANSI TYAGI return x; } Call by value and call by reference There are two way through which we can pass the arguments to the function such as call by value and call by reference. 1. Call by value In the call by value copy of the actual argument is passed to the formal argument and the operation is done on formal argument.When the function is called by ‘call by value’ method.  It does not affect content of the actual argument. Changes made to formal argument are local to block of called function so when the control back to calling function the changes made is vanish.  Example:- main() { int x,y; change(int,int); printf(“enter two values:n”); scanf(“%d%d”,&x,&y);
  • 13. MANSI TYAGI change(x ,y); printf(“value of x=%d and y=%dn”,x ,y); } change(int a,int b); { int k; k=a; a=b; b=k; } Output: enter two values: 12 ,23 Value of x=12 and y=23 2. Call by reference Instead of passing the value of variable, address or reference is passed and the function operate on address of the variable rather than value.  Here formal argument is alter to the actual argument, it means formal arguments calls the actual arguments.  Example:- void main() { int a,b;
  • 14. MANSI TYAGI change(int *,int*); printf(“enter two values:n”); scanf(“%d%d”,&a,&b); change(&a,&b); printf(“after changing two value of a=%d and b=%dn:”a,b); } change(int *a, int *b) { int k; k=*a; *a=*b; *b= k; printf(“value in this function a=%d and b=%dn”,*a,*b); } Output: enter two values: 12, 32 Value in this function a=32 and b=12 After changing two value of a=32 and b=12  So here instead of passing value of the variable, directly passing address of the variables. Formal argument directly access the value and swapping is possible even after calling a function.
  • 15. MANSI TYAGI STORAGE CLASSES: The storage class in C provides the complete information about the location and visibility of variables.  To define a variable in C one needs to mention not only its but also its storage class. In other words , not only do all variables have a data type, they also have a storage class.  If we do not specify the storage class of a variable in its declaration , the compiler will resume a storage class dependent on the context in which the variable is used. Thus C has got certain default storage classes.  Moreover, a variables storage class tells us:  Where the variable would be stored.  What will be the initial value of the variable , if the initial value is not specifically assigned( i.e. the default initial value)  What is the scope of the variable i.e in which function the value of the variable would be available.  What is the life of the variable, i.e. how long would the variable exist. TYPES OF STORAGE CLASSES: a) Automatic storage class. b) Register storage class. c) Static storage class. d) External storage class.
  • 16. MANSI TYAGI 1. AUTOMATIC VARIABLES: Automatic variables are declared inside a function in which they are used they are to be utilized. They are created when the function is called and destroyed automatically when they are declared. Because of this property, automatic variables are also referred to as local or internal variables. Syntax : We may also use the key word auto to declare automatic variables. main() { auto int n; Statements; } FEATURES OF AUTOMATIC 1.Storage : Memory 2.Default initial value : A garbage value 3.Scope: Local to the block in which it is declared. 4.Life: As long as the program control remains within the block in which it is declared.
  • 17. MANSI TYAGI 2.REGISTERS STORAGE CLASSES : We can tell the compiler that a variable should be kept in one of the machine’s register, instead of keeping in the memory. Since a register access is much faster than a memory access. Keeping the frequently accessed variables in the register will lead to faster execution of programs. Syntax : register int i; 3.STATIC STORAGE CLASS: As the name suggests, the value of static variables persists until the end of the program. A variable can be declared static using the keyword static. A static variables may be either an internal type or an external type, depending on the place of declaration. main() { int i; FEATURES OF REGISTERS 1.Storage : Memory 2.Default initial value : A garbage value 3.Scope: Local to the block in which it is declared. 4.Life: As long as the program control remains within the block in which it is declared.
  • 18. MANSI TYAGI for(i=1;i<=3;i++) fun(); } fun() { static int x=5; x=x+3; printf(“x=%dn”, x); } 4.EXTERNAL STORAGE CLASS: Variables that are both alive and active throughout the entire program are known as external variables. They are also known as global variables. External variables are declared outside a function. FEATURES OF STATIC 1.Storage : Memory 2.Default initial value : ZERO 3.Scope: Local to the block in which it is declared. 4.Life:Variables retains its value betwwn different functions calls. FEATURES OF STATIC 1.Storage : Memory 2.Default initial value : ZERO 3.Scope: In all functions of a program i.e: global 4.Life: Throughout the program execution.
  • 19. MANSI TYAGI Recursion The function called by itself (inside function body) is called recursive function and this process often referred as recursion.  In recursion calling function and called function are same.  It is powerful technique of writing complicated algorithm in easiest way.  According to recursion problem is defined in term of itself. Here statement with in body of the function calls the same function and same times it is called as circular definition.  In other words recursion is the process of defining something in form of itself. Important conditions: There are two important conditions that must be satisfied by any recursive procedure. 1.Each time a procedure calls itself, it must be nearer to a solution. 2.There must be a decision criterion for stopping the computation. Types of recursion: There are two types of recursions. 1.The first type concerns recursively defined functions. Example of this kind is the Factorial function. 2.The second type of recursion is the recursive use of a procedure. Syntax: main () { rec(); /*function call*/ rec(); rec();
  • 20. MANSI TYAGI Ex:- /*calculate factorial of a no.using recursion*/ #include<stdio.h> #include<conio.h> int fact(int); void main() { int num; printf(“enter a number”); scanf(“%d”,&num); f=fact(num); printf(“factorial is =%dn”f); } fact (int num) { If (num==0||num==1) return 1; else return(num*fact(num-1)); }
  • 21. MANSI TYAGI IMPORTANT QUESTIONS Q1. What is user defined functions?what is recursion?what are the conditions for recursion to be convergent?write a recursive function to compute factorial of a given number?Make use of this function to compute the value of NCr. Q2.Distinguish between Call by value and Call by reference methods of parameter passings by giving suitable example? Q3.Explain the concept of Storage classes.Explain eaxh with an example. Q4.Explain the concept of variables? Q5.What is Recursion? Explain with its suitable example. Q6. What do you understand by functions?Explain with its types. Q7. What is user defined functions?How can you return a value from a function?Explain with an example .Also discuss different methods to pass parameters to a function by giving suitable examples.