SlideShare a Scribd company logo
1 of 21
Functions in C
 A brief study
Functions
• Function is a self-contained block or a sub-
  program of one or more statements that
  performs a special task when called.
Example of functions
• Hotel management

  – Front Office

  – Reservation

  – Housekeeping

  – Telephone
Hotel management
Hotel
Customer()
   {
      House_keeping(); //Function call
    }
House_keeping() //Function definition
   {
      Cleans rooms;
   }
Hotel
Customer() //calling function
   {
      House_keeping(); //Function call
    }
House_keeping() //called function
   {
      Cleans rooms;
   }
Add two numbers
main()
{
  int a,b;
  int c;
  printf(“Enter the value of a”);
  scanf(“%d”,&a);
  printf(“Enter the value of b”);
  scanf(“%d”,&b);
  c=a+b;
  printf(“Answer is:%d”,c);
}
Add two numbers using functions
main()
{                                 add(x,y)
  int a,b;                        {
  int c;                            z=x+y;
  printf(“Enter the value of a”);   printf(“%d”,z);
  scanf(“%d”,&a);                 }
  printf(“Enter the value of b”);
  scanf(“%d”,&b);
  add(a,b);
}
Arguments/Parameters
• Arguments are used mostly in functions.
• it can be any input parameter which a
  function can use to do it's work.
• Example:      sin(x) sin is a function
                       x is it's argument.
Arguments/Parameters
• Actual arguments:
        • Arguments of calling function

• Formal arguments:
       • Arguments of called function
Add two numbers using functions
main()                               formal arguments
{                                 add(x,y)
  int a,b;                        {
  int c;                              z=x+y;
  printf(“Enter the value of a”);     printf(“%d”,z);
  scanf(“%d”,&a);                  }
  printf(“Enter the value of b”);
  scanf(“%d”,&b);
  add(a,b); //function call
}       actual arguments
Argument/Parameter list
a=2
b=4
      add(a,b);



                    add(x,y)
                               x=2
                               y=4
return statement
• function uses return statement to return the
  value to the called function.
• Exit from the called function.
        return(expression);
Hotel
Customer() //calling function
   {
      House_keeping(); //Function call
    }
House_keeping() //called function
   {
      Cleans rooms;
      return 0;
   }
Hotel
Customer() //calling function
   {
      Front_office(Money); //Function call
    }
Front_office(Money) //called function
   {
      return receipt;
   }
Types of functions
1.   No arguments and no return type
2.   No arguments and return type
3.   With arguments and no return type
4.   With arguments and return type
Passing arguments
• The arguments passed to function can be of two
  types.
       1. Values passed – Call by value
       2. Address passed – Call by reference
Call by value
• main()
  {
  int x=50, y=70;
  add(x,y);
  }

  add(int x1,int y1)
  {
  int z1;
  z1=x1+y1;
  printf(“%d”,z1);
  }
Call by reference
• main()
  {
  int x=50, y=70;
  add(&x,&y);
  }

  add(int *x1,int *y1)
  {
  int z1;
  z1=x1+y1;
  printf(“%d”,z1);
  }
Call by reference
• Address is passed using symbol ‘&’
  value is accessed using symbol ‘*’

  x=50          &x=2000         *x=50
  y=70          &y=2008         *y=70
Thank you

More Related Content

What's hot (20)

Function in c program
Function in c programFunction in c program
Function in c program
 
Function in c
Function in cFunction in c
Function in c
 
Function lecture
Function lectureFunction lecture
Function lecture
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Function
FunctionFunction
Function
 
Function & Recursion in C
Function & Recursion in CFunction & Recursion in C
Function & Recursion in C
 
C function presentation
C function presentationC function presentation
C function presentation
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Functions
FunctionsFunctions
Functions
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
functions in C and types
functions in C and typesfunctions in C and types
functions in C and types
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
Pre defined Functions in C
Pre defined Functions in CPre defined Functions in C
Pre defined Functions in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
C++ Function
C++ FunctionC++ Function
C++ Function
 

Viewers also liked

Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerGaurav Verma
 
Function C
Function CFunction C
Function CWarawut
 
Embedded systems ppt iv part d
Embedded systems ppt iv   part dEmbedded systems ppt iv   part d
Embedded systems ppt iv part danishgoel
 
Embedded c programming guide e book atmel 8051 / 89c51 /89c52
Embedded c programming guide e book atmel 8051 / 89c51 /89c52Embedded c programming guide e book atmel 8051 / 89c51 /89c52
Embedded c programming guide e book atmel 8051 / 89c51 /89c52Raghav Shetty
 
Embedded systems ppt iv part c
Embedded systems ppt iv   part cEmbedded systems ppt iv   part c
Embedded systems ppt iv part canishgoel
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Sivaranjan Goswami
 
Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiMuhammad Abdullah
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED CAman Sharma
 
Embedded c lab and keil c manual
Embedded  c  lab  and keil c  manualEmbedded  c  lab  and keil c  manual
Embedded c lab and keil c manualHari K
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil KawareProf. Swapnil V. Kaware
 
Question paper with solution the 8051 microcontroller based embedded systems...
Question paper with solution  the 8051 microcontroller based embedded systems...Question paper with solution  the 8051 microcontroller based embedded systems...
Question paper with solution the 8051 microcontroller based embedded systems...manishpatel_79
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingAnkur Mahajan
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller NotesDr.YNM
 
8051 experiments1
8051 experiments18051 experiments1
8051 experiments1tt_aljobory
 
Writing c code for the 8051
Writing c code for the 8051Writing c code for the 8051
Writing c code for the 8051Quản Minh Tú
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051techbed
 

Viewers also liked (20)

Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
Function C
Function CFunction C
Function C
 
Embedded systems ppt iv part d
Embedded systems ppt iv   part dEmbedded systems ppt iv   part d
Embedded systems ppt iv part d
 
Embedded c programming guide e book atmel 8051 / 89c51 /89c52
Embedded c programming guide e book atmel 8051 / 89c51 /89c52Embedded c programming guide e book atmel 8051 / 89c51 /89c52
Embedded c programming guide e book atmel 8051 / 89c51 /89c52
 
Embedded systems ppt iv part c
Embedded systems ppt iv   part cEmbedded systems ppt iv   part c
Embedded systems ppt iv part c
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
 
8051 io interface
8051 io interface8051 io interface
8051 io interface
 
Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidi
 
8051 Presentation
8051 Presentation8051 Presentation
8051 Presentation
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
 
Embedded c lab and keil c manual
Embedded  c  lab  and keil c  manualEmbedded  c  lab  and keil c  manual
Embedded c lab and keil c manual
 
Embedded c
Embedded cEmbedded c
Embedded c
 
8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware8051 Microcontroller PPT's By Er. Swapnil Kaware
8051 Microcontroller PPT's By Er. Swapnil Kaware
 
Question paper with solution the 8051 microcontroller based embedded systems...
Question paper with solution  the 8051 microcontroller based embedded systems...Question paper with solution  the 8051 microcontroller based embedded systems...
Question paper with solution the 8051 microcontroller based embedded systems...
 
Microcontroller 8051 and its interfacing
Microcontroller 8051 and its interfacingMicrocontroller 8051 and its interfacing
Microcontroller 8051 and its interfacing
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
 
8051 experiments1
8051 experiments18051 experiments1
8051 experiments1
 
Writing c code for the 8051
Writing c code for the 8051Writing c code for the 8051
Writing c code for the 8051
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051
 

Similar to Functions in C

Similar to Functions in C (20)

Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college
 
Functions
FunctionsFunctions
Functions
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
function in c
function in cfunction in c
function in c
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
CHAPTER 6
CHAPTER 6CHAPTER 6
CHAPTER 6
 
4th unit full
4th unit full4th unit full
4th unit full
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Array Cont
Array ContArray Cont
Array Cont
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 

Recently uploaded

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Recently uploaded (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Functions in C

  • 1. Functions in C A brief study
  • 2. Functions • Function is a self-contained block or a sub- program of one or more statements that performs a special task when called.
  • 3. Example of functions • Hotel management – Front Office – Reservation – Housekeeping – Telephone
  • 5. Hotel Customer() { House_keeping(); //Function call } House_keeping() //Function definition { Cleans rooms; }
  • 6. Hotel Customer() //calling function { House_keeping(); //Function call } House_keeping() //called function { Cleans rooms; }
  • 7. Add two numbers main() { int a,b; int c; printf(“Enter the value of a”); scanf(“%d”,&a); printf(“Enter the value of b”); scanf(“%d”,&b); c=a+b; printf(“Answer is:%d”,c); }
  • 8. Add two numbers using functions main() { add(x,y) int a,b; { int c; z=x+y; printf(“Enter the value of a”); printf(“%d”,z); scanf(“%d”,&a); } printf(“Enter the value of b”); scanf(“%d”,&b); add(a,b); }
  • 9. Arguments/Parameters • Arguments are used mostly in functions. • it can be any input parameter which a function can use to do it's work. • Example: sin(x) sin is a function x is it's argument.
  • 10. Arguments/Parameters • Actual arguments: • Arguments of calling function • Formal arguments: • Arguments of called function
  • 11. Add two numbers using functions main() formal arguments { add(x,y) int a,b; { int c; z=x+y; printf(“Enter the value of a”); printf(“%d”,z); scanf(“%d”,&a); } printf(“Enter the value of b”); scanf(“%d”,&b); add(a,b); //function call } actual arguments
  • 12. Argument/Parameter list a=2 b=4 add(a,b); add(x,y) x=2 y=4
  • 13. return statement • function uses return statement to return the value to the called function. • Exit from the called function. return(expression);
  • 14. Hotel Customer() //calling function { House_keeping(); //Function call } House_keeping() //called function { Cleans rooms; return 0; }
  • 15. Hotel Customer() //calling function { Front_office(Money); //Function call } Front_office(Money) //called function { return receipt; }
  • 16. Types of functions 1. No arguments and no return type 2. No arguments and return type 3. With arguments and no return type 4. With arguments and return type
  • 17. Passing arguments • The arguments passed to function can be of two types. 1. Values passed – Call by value 2. Address passed – Call by reference
  • 18. Call by value • main() { int x=50, y=70; add(x,y); } add(int x1,int y1) { int z1; z1=x1+y1; printf(“%d”,z1); }
  • 19. Call by reference • main() { int x=50, y=70; add(&x,&y); } add(int *x1,int *y1) { int z1; z1=x1+y1; printf(“%d”,z1); }
  • 20. Call by reference • Address is passed using symbol ‘&’ value is accessed using symbol ‘*’ x=50 &x=2000 *x=50 y=70 &y=2008 *y=70