SlideShare a Scribd company logo
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

C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 

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

Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidi
Muhammad Abdullah
 
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
Prof. Swapnil V. Kaware
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
Dr.YNM
 
Writing c code for the 8051
Writing c code for the 8051Writing c code for the 8051
Writing c code for the 8051
Quản Minh Tú
 

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
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Array Cont
Array ContArray Cont
Array Cont
 

Recently uploaded

Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
YibeltalNibretu
 
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)

Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
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
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
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
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
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...
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
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
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
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
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
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
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 

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