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
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1
Arslan Hussain
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
Md. Imran Hossain Showrov
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
SKUP1
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
Paras Patel
 
Algorithm and Flowcharts
Algorithm and FlowchartsAlgorithm and Flowcharts
Algorithm and Flowcharts
Dr. SURBHI SAROHA
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
Presentation on C programming language
Presentation on C programming languagePresentation on C programming language
Presentation on C programming language
Ashmita Tuition Center
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
Darshan Patel
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
avikdhupar
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Programming Fundamental Slide No.1
Programming Fundamental Slide No.1Programming Fundamental Slide No.1
Programming Fundamental Slide No.1
Arslan Hussain
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
Md. Imran Hossain Showrov
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
SKUP1
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
Paras Patel
 
Presentation on C programming language
Presentation on C programming languagePresentation on C programming language
Presentation on C programming language
Ashmita Tuition Center
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
avikdhupar
 

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
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
BoomBoomers
 
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
 
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)

How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 

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.
  翻译: