SlideShare a Scribd company logo
FUNCTION IN CMS. LOTHE SAVITAA.
DEPT OF COMPUTER SCIENCE
VASANTRAO NAIK MAHAVIDYALAYA, AURANGABAD..
TO STUDY…
 Introduction, types of functions.
 Defining functions, Arguments,
 Function prototype, actual parameters and formal
parameters,
 Calling function, Returning function results,
 Call by value, Recursion.
2FUNCTION IN C PROGRAMMING
INTRODUCTION
 C functions are basic building blocks in a program.
 All C programs are written using functions to
improve re-usability, understandability and to keep
track on them.
3FUNCTION IN C PROGRAMMING
WHAT IS FUNCTION?
 A large C program is divided into basic building blocks
called C function.
 C function contains set of instructions enclosed by “{ }”
which performs specific operation in a C program.
4
FUNCTION IN C PROGRAMMING
USES OF C FUNCTIONS:
C functions are used to avoid rewriting same logic/code again and again in a
program.
There is no limit in calling C functions to make use of same functionality
wherever required.
We can call functions any number of times in a program and from any place in
a program.
A large C program can easily be tracked when it is divided into functions.
The core concept of C functions are, re-usability, dividing a big task into small
pieces to achieve the functionality and to improve understandability of very
large C programs. 5
FUNCTION IN C PROGRAMMING
FUNCTION
6FUNCTION IN C PROGRAMMING
PROGRAM SHOWING FUNCTION IN C
#include<stdio.h>
float square ( float x ); // function prototype, also called function declaration
int main( )
{
float m, n ;
printf ( "n Enter some number for finding square n");
scanf ( "%f", &m ) ;
n = square ( m ) ; // function call
printf ( "nSquare of the given number %f is %f",m,n );
}
float square ( float x ) // function definition
{
float p ;
p = x * x ;
return ( p ) ;
}
7FUNCTION IN C PROGRAMMING
HOW TO CALL C FUNCTIONS IN A
PROGRAM?
Call by value
Call by reference
THERE ARE
TWO WAYS
THAT A C
FUNCTION CAN
BE CALLED
FROM A
PROGRAM.
THEY ARE,
8FUNCTION IN C PROGRAMMING
CALL BY VALUE
In call by value method, the value of the variable is passed to the
function as parameter.
The value of the actual parameter can not be modified by formal
parameter.
Different Memory is allocated for both actual and formal
parameters. Because, value of actual parameter is copied to
formal parameter.
9FUNCTION IN C PROGRAMMING
Actual parameter – This is the argument which
is used in function call.
Formal parameter – This is the argument
which is used in function definition
10FUNCTION IN C PROGRAMMING
PROGRAM FOR CALL BY VALUE
#include<stdio.h>
void swap(int a, int b); // function prototype, also called function declaration
int main()
{
int m = 22, n = 44;
printf(" values before swap m = %d nand n = %d", m, n); // calling swap function by value
swap(m, n);
}
void swap(int a, int b)
{
int tmp;
tmp = a;
a = b;
b = tmp;
printf(" nvalues after swap m = %dn and n = %d", a, b);
}
11FUNCTION IN C PROGRAMMING
CALL BY REFERENCE
In call by reference method, the address of the variable is
passed to the function as parameter.
The value of the actual parameter can be modified by
formal parameter.
Same memory is used for both actual and formal
parameters since only address is used by both
parameters.
12FUNCTION IN C PROGRAMMING
EXAMPLE SHOWING CALL BY REFERENCE
#include<stdio.h>
void swap(int *a, int *b); // function prototype, also called function declaration
int main()
{ int m = 22, n = 44;
printf("values before swap m = %d n and n = %d",m,n); // calling swap function by
reference
swap(&m, &n);
}
void swap(int *a, int *b)
{
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
printf("n values after swap a = %d nand b = %d", *a, *b);
}
13
FUNCTION IN C PROGRAMMING
RECURSION
 Recursion is the process of repeating items in a self-similar way. In
programming languages, if a program allows you to call a function inside the
same function, then it is called a recursive call of the function.
 Common examples of where recursion is used
 Walking recursive data structures such as linked lists, binary trees, etc.
 Exploring possible scenarios in games such as chess
Recursion always consists of two main parts. A terminating case that indicates
when the recursion will finish and a call to itself that must make progress
towards the terminating case. 14
FUNCTION IN C PROGRAMMING
SYNTAX
int main()
{
callme( );
...
return 0;
}
void rec( )
{
statement 1;
...
rec( );
}
15FUNCTION IN C PROGRAMMING
WORKING OF RECURSION
// A C++ program to demonstrate working of recursion
#include<stdio.h>
void printFun(int test)
{
if (test < 1)
return;
else
{
cout << test << " ";
printFun(test-1); // statement 2
cout << test << " ";
return;
}
}
int main()
{
int test = 3;
printFun(test);
}
16
FUNCTION IN C PROGRAMMING
REFERENCES
 https://www.tutorialspoint.com/cprogramming/c_recursion.
htm
 “Yashavant P. Kanetkar”, Let Us C - 14th Edition BPB
Publications ©2016, ISBN:8183331637 9788183331630
 https://fresh2refresh.com/
17FUNCTION IN C PROGRAMMING
THANK YOU

More Related Content

What's hot

constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
Sahithi Naraparaju
 

What's hot (20)

Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Friend function
Friend functionFriend function
Friend function
 
Function
FunctionFunction
Function
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
Array and string
Array and stringArray and string
Array and string
 
functions of C++
functions of C++functions of C++
functions of C++
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Strings
StringsStrings
Strings
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Strings in C
Strings in CStrings in C
Strings in C
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 

Similar to Function in c

function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
kushwahashivam413
 

Similar to Function in c (20)

Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
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
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
 
9. DBMS Experiment Laboratory PresentationPPT
9. DBMS Experiment Laboratory PresentationPPT9. DBMS Experiment Laboratory PresentationPPT
9. DBMS Experiment Laboratory PresentationPPT
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
C function
C functionC function
C function
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
[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++
 
Function
FunctionFunction
Function
 
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
 

More from savitamhaske (8)

Introduction html
Introduction htmlIntroduction html
Introduction html
 
Specialized estimation tech
Specialized estimation techSpecialized estimation tech
Specialized estimation tech
 
8086 microprocessor
8086 microprocessor8086 microprocessor
8086 microprocessor
 
Tables
TablesTables
Tables
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Introduction to toc and compiler
Introduction to toc and compilerIntroduction to toc and compiler
Introduction to toc and compiler
 
Decision control and iterative statements
Decision control and iterative statementsDecision control and iterative statements
Decision control and iterative statements
 
Programming in C- Introduction
Programming in C- IntroductionProgramming in C- Introduction
Programming in C- Introduction
 

Recently uploaded

Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
Avinash Rai
 

Recently uploaded (20)

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 

Function in c

  • 1. FUNCTION IN CMS. LOTHE SAVITAA. DEPT OF COMPUTER SCIENCE VASANTRAO NAIK MAHAVIDYALAYA, AURANGABAD..
  • 2. TO STUDY…  Introduction, types of functions.  Defining functions, Arguments,  Function prototype, actual parameters and formal parameters,  Calling function, Returning function results,  Call by value, Recursion. 2FUNCTION IN C PROGRAMMING
  • 3. INTRODUCTION  C functions are basic building blocks in a program.  All C programs are written using functions to improve re-usability, understandability and to keep track on them. 3FUNCTION IN C PROGRAMMING
  • 4. WHAT IS FUNCTION?  A large C program is divided into basic building blocks called C function.  C function contains set of instructions enclosed by “{ }” which performs specific operation in a C program. 4 FUNCTION IN C PROGRAMMING
  • 5. USES OF C FUNCTIONS: C functions are used to avoid rewriting same logic/code again and again in a program. There is no limit in calling C functions to make use of same functionality wherever required. We can call functions any number of times in a program and from any place in a program. A large C program can easily be tracked when it is divided into functions. The core concept of C functions are, re-usability, dividing a big task into small pieces to achieve the functionality and to improve understandability of very large C programs. 5 FUNCTION IN C PROGRAMMING
  • 7. PROGRAM SHOWING FUNCTION IN C #include<stdio.h> float square ( float x ); // function prototype, also called function declaration int main( ) { float m, n ; printf ( "n Enter some number for finding square n"); scanf ( "%f", &m ) ; n = square ( m ) ; // function call printf ( "nSquare of the given number %f is %f",m,n ); } float square ( float x ) // function definition { float p ; p = x * x ; return ( p ) ; } 7FUNCTION IN C PROGRAMMING
  • 8. HOW TO CALL C FUNCTIONS IN A PROGRAM? Call by value Call by reference THERE ARE TWO WAYS THAT A C FUNCTION CAN BE CALLED FROM A PROGRAM. THEY ARE, 8FUNCTION IN C PROGRAMMING
  • 9. CALL BY VALUE In call by value method, the value of the variable is passed to the function as parameter. The value of the actual parameter can not be modified by formal parameter. Different Memory is allocated for both actual and formal parameters. Because, value of actual parameter is copied to formal parameter. 9FUNCTION IN C PROGRAMMING
  • 10. Actual parameter – This is the argument which is used in function call. Formal parameter – This is the argument which is used in function definition 10FUNCTION IN C PROGRAMMING
  • 11. PROGRAM FOR CALL BY VALUE #include<stdio.h> void swap(int a, int b); // function prototype, also called function declaration int main() { int m = 22, n = 44; printf(" values before swap m = %d nand n = %d", m, n); // calling swap function by value swap(m, n); } void swap(int a, int b) { int tmp; tmp = a; a = b; b = tmp; printf(" nvalues after swap m = %dn and n = %d", a, b); } 11FUNCTION IN C PROGRAMMING
  • 12. CALL BY REFERENCE In call by reference method, the address of the variable is passed to the function as parameter. The value of the actual parameter can be modified by formal parameter. Same memory is used for both actual and formal parameters since only address is used by both parameters. 12FUNCTION IN C PROGRAMMING
  • 13. EXAMPLE SHOWING CALL BY REFERENCE #include<stdio.h> void swap(int *a, int *b); // function prototype, also called function declaration int main() { int m = 22, n = 44; printf("values before swap m = %d n and n = %d",m,n); // calling swap function by reference swap(&m, &n); } void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp; printf("n values after swap a = %d nand b = %d", *a, *b); } 13 FUNCTION IN C PROGRAMMING
  • 14. RECURSION  Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.  Common examples of where recursion is used  Walking recursive data structures such as linked lists, binary trees, etc.  Exploring possible scenarios in games such as chess Recursion always consists of two main parts. A terminating case that indicates when the recursion will finish and a call to itself that must make progress towards the terminating case. 14 FUNCTION IN C PROGRAMMING
  • 15. SYNTAX int main() { callme( ); ... return 0; } void rec( ) { statement 1; ... rec( ); } 15FUNCTION IN C PROGRAMMING
  • 16. WORKING OF RECURSION // A C++ program to demonstrate working of recursion #include<stdio.h> void printFun(int test) { if (test < 1) return; else { cout << test << " "; printFun(test-1); // statement 2 cout << test << " "; return; } } int main() { int test = 3; printFun(test); } 16 FUNCTION IN C PROGRAMMING
  • 17. REFERENCES  https://www.tutorialspoint.com/cprogramming/c_recursion. htm  “Yashavant P. Kanetkar”, Let Us C - 14th Edition BPB Publications ©2016, ISBN:8183331637 9788183331630  https://fresh2refresh.com/ 17FUNCTION IN C PROGRAMMING