SlideShare a Scribd company logo
1 of 20
Presentation on
Function
Function:
A function is a group of statements that together
perform a task. Every C program has at least one
function, which is main(), and all the most trivial
programs can define additional functions.
Defining a Function:
The general form of a function definition in C
programming language is as follows:
return_type function_name( parameter list )
{
body of the function
}
Function Return Types
Can be any of C’s data type:
char
int
float
long………
Examples:
int func1(...) /* Returns a type int. */
float func2(...) /* Returns a type float. */
void func3(...) /* Returns nothing. */
Function Prototype:
Function prototypes are usually written at the beginning of
a program, ahead of any programmer defined function.
Function Prototype Example:
 double squared( double number );
 void print_report( int report_number );
 int get_menu_choice( void);
#include <stdio.h>
Void main (int a); /*function prototype*/
Main()
{
}
Function calling:
#include <stdio.h>
int show ( ) {
printf(“It’s a function”);
{
Int main ( ) {
Show (); function call
}
Function Arguments:
If a function is to use arguments, it must declare
variables that accept the values of the arguments.
These variables are called the formal parameters
of the function.
The formal parameters behave like other local
variables inside the function and are created upon
entry into the function and destroyed upon exit.
While calling a function, there are two ways that
arguments can be passed to a function:
Example of Parameter and Argument:
Main () {
//Argument
add (10, 20),
}
// Parameter
Add (int i, int j) {
int j;
j=i+j;
}
Actual and Formal parameter:
#include <stdio.h>
void main(void)
{
void test_function(int) ;
test_function(1) ;  actual parameter
}
Void test_function(i_recd_value) formal parameter
int i_recd_value ;
{
cout << "Value passed = " << i_recd_value ;
return ;
}
Local Variables:
Variables that are declared inside a function or block
are called local variables. They can be used only by
statements that are inside that function or block of
code. Local variables are not known to functions
outside their own. Following is the example using
local variables. Here all the variables a, b and c are
local to main() function.
Global Variables:
Global variables are defined outside of a function,
usually on top of the program. The global variables will
hold their value throughout the lifetime of your
program and they can be accessed inside any of the
functions defined for the program.
A global variable can be accessed by any function. That
is, a global variable is available for use throughout your
entire program after its declaration. Following is the
example using global and local variables:
Local variable and Actual variable:
#include <stdio.h>
void show (){
int i=5; //local variable
Printf(“%dn”,i);
}
int main () {
int i=2; //Actual variable
Printf(“%dn”,i);
show ();
}
Call by Value:
Call by Value, means that a copy of the data is made
and stored by way of the name of the parameter.
Any changes to the parameter have NO affect on
data in the calling function.
Example Call by value:
#include<stdio.h>
void c(int n, int m) {
int temp;
temp = n;
n = m; m = temp;
}
int main() {
int n=50,m=70;
c(n,m);
printf("nNumber : %d",n);
printf("nNumber 2 : %d",m);
return(0); }
Call by Reference:
A reference parameter "refers" to the original data in
the calling function. Thus any changes made to the
parameter are ALSO MADE TO THE ORIGINAL
variable.
Example of Call by Reference:
#include <stdio.h>
void swap(int *x, int *y);
int main () {
int a = 100; int b = 200;
printf("Before swap, value of a : %dn", a );
printf("Before swap, value of b : %dn", b );
swap(&a, &b);
printf("After swap, value of a : %dn", a );
printf("After swap, value of b : %dn", b );
return 0;
}
Array of function:
#include <stdio.h>
float average(float a[]);
int main(){
float avg, c[]={23.4, 55, 22.6, 3, 40.5, 18}; avg=average(c);
printf("Average age=%.2f",avg);
return 0; }
float average(float a[]){
int i;
float avg, sum=0.0;
for(i=0;i<6;++i){ sum+=a[i]; }
avg =(sum/6);
return avg;
}
Recursion:
Recursion defines a function in terms of itself.
It is a programming technique in which a function calls
itself.
A recursive function calls itself repeatedly, with different
argument values each time.
Some argument values cause the recursive method to
return without calling itself. This is the base case.
Either omitting the base case or writing the recursion
step incorrectly will cause infinite recursion (stack
overflow error).
Example:
#include <stdio.h>
int sum(int n);
int main(){
int num,add;
printf("Enter a positive integer:n");
scanf("%d",&num);
add=sum(num);
printf("sum=%d",add);
}
int sum(int n){
if(n==0)
return n;
else
return n+sum(n-1); /*self call to function sum() */
}
Thank You
Md. Abu Zaman
Daffodil International
University

More Related Content

What's hot (20)

Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
C programming
C programmingC programming
C programming
 
Built in function
Built in functionBuilt in function
Built in function
 
Dictionaries in Python
Dictionaries in PythonDictionaries in Python
Dictionaries in Python
 
C functions
C functionsC functions
C functions
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
Function in c
Function in cFunction in c
Function in c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
Friend functions
Friend functions Friend functions
Friend functions
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 

Similar to Presentation on function (20)

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
 
Function in c
Function in cFunction in c
Function in c
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
C functions list
C functions listC functions list
C functions list
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
Functions in c
Functions in cFunctions in c
Functions in c
 
C function
C functionC function
C function
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
functions
functionsfunctions
functions
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
Functions
Functions Functions
Functions
 

Recently uploaded

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

Presentation on function

  • 2. Function: A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. Defining a Function: The general form of a function definition in C programming language is as follows: return_type function_name( parameter list ) { body of the function }
  • 3. Function Return Types Can be any of C’s data type: char int float long……… Examples: int func1(...) /* Returns a type int. */ float func2(...) /* Returns a type float. */ void func3(...) /* Returns nothing. */
  • 4. Function Prototype: Function prototypes are usually written at the beginning of a program, ahead of any programmer defined function. Function Prototype Example:  double squared( double number );  void print_report( int report_number );  int get_menu_choice( void); #include <stdio.h> Void main (int a); /*function prototype*/ Main() { }
  • 5. Function calling: #include <stdio.h> int show ( ) { printf(“It’s a function”); { Int main ( ) { Show (); function call }
  • 6. Function Arguments: If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables are called the formal parameters of the function. The formal parameters behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit. While calling a function, there are two ways that arguments can be passed to a function:
  • 7. Example of Parameter and Argument: Main () { //Argument add (10, 20), } // Parameter Add (int i, int j) { int j; j=i+j; }
  • 8. Actual and Formal parameter: #include <stdio.h> void main(void) { void test_function(int) ; test_function(1) ; actual parameter } Void test_function(i_recd_value) formal parameter int i_recd_value ; { cout << "Value passed = " << i_recd_value ; return ; }
  • 9. Local Variables: Variables that are declared inside a function or block are called local variables. They can be used only by statements that are inside that function or block of code. Local variables are not known to functions outside their own. Following is the example using local variables. Here all the variables a, b and c are local to main() function.
  • 10. Global Variables: Global variables are defined outside of a function, usually on top of the program. The global variables will hold their value throughout the lifetime of your program and they can be accessed inside any of the functions defined for the program. A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration. Following is the example using global and local variables:
  • 11. Local variable and Actual variable: #include <stdio.h> void show (){ int i=5; //local variable Printf(“%dn”,i); } int main () { int i=2; //Actual variable Printf(“%dn”,i); show (); }
  • 12. Call by Value: Call by Value, means that a copy of the data is made and stored by way of the name of the parameter. Any changes to the parameter have NO affect on data in the calling function.
  • 13. Example Call by value: #include<stdio.h> void c(int n, int m) { int temp; temp = n; n = m; m = temp; } int main() { int n=50,m=70; c(n,m); printf("nNumber : %d",n); printf("nNumber 2 : %d",m); return(0); }
  • 14. Call by Reference: A reference parameter "refers" to the original data in the calling function. Thus any changes made to the parameter are ALSO MADE TO THE ORIGINAL variable.
  • 15. Example of Call by Reference: #include <stdio.h> void swap(int *x, int *y); int main () { int a = 100; int b = 200; printf("Before swap, value of a : %dn", a ); printf("Before swap, value of b : %dn", b ); swap(&a, &b); printf("After swap, value of a : %dn", a ); printf("After swap, value of b : %dn", b ); return 0; }
  • 16. Array of function: #include <stdio.h> float average(float a[]); int main(){ float avg, c[]={23.4, 55, 22.6, 3, 40.5, 18}; avg=average(c); printf("Average age=%.2f",avg); return 0; } float average(float a[]){ int i; float avg, sum=0.0; for(i=0;i<6;++i){ sum+=a[i]; } avg =(sum/6); return avg; }
  • 17. Recursion: Recursion defines a function in terms of itself. It is a programming technique in which a function calls itself. A recursive function calls itself repeatedly, with different argument values each time. Some argument values cause the recursive method to return without calling itself. This is the base case. Either omitting the base case or writing the recursion step incorrectly will cause infinite recursion (stack overflow error).
  • 18. Example: #include <stdio.h> int sum(int n); int main(){ int num,add; printf("Enter a positive integer:n"); scanf("%d",&num); add=sum(num); printf("sum=%d",add); } int sum(int n){ if(n==0) return n; else return n+sum(n-1); /*self call to function sum() */ }
  • 20. Md. Abu Zaman Daffodil International University