what is a function? functions are nothing but sub-programs of a program. is a part of a program...
DESCRIPTION
Functions exhibit the feature of MODULARITY in OOP (Object Oriented programming). What is Modularity? The act of breaking up larger programs into smaller unit is called modularity. S. Kiran PGT(Comp. Science), KV, MalleswaramTRANSCRIPT
![Page 1: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/1.jpg)
![Page 2: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/2.jpg)
What is a function?
Functions are nothing but sub-programs of a program .
Is a part of a program which performs a particular task as desired by the programmer.
It can be called anywhere in the program.
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 3: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/3.jpg)
Functions exhibit the feature of MODULARITY in OOP (Object Oriented programming).
What is Modularity?
The act of breaking up larger programs into smaller unit is called modularity.
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 4: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/4.jpg)
Advantages of using Functions
Easier to maintain, update and debug.
Enhances readability of the program
Reusability of code
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 5: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/5.jpg)
TYPES OF FUNCTIONS
BUILT – IN FUNCTIONS
USER DEFINED FUNCTIONS
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 6: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/6.jpg)
BUILT – IN FUNCTIONS
These are part of the compiler package, which are defined in the standard library files also called header files.
For e.g..,string.h header file contains definition for the following functions.strlen(), strcmp(), strrev () etc.
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 7: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/7.jpg)
USER DEFINED FUNCTIONS
Are functions defined by the programmer.
That is YOU.
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 8: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/8.jpg)
FUNCTION DEFINITIONA function must be defined before it is used
anywhere in the program.
Three important things that must be remembered
1. Function prototype2. Function call3. Function Definition
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 9: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/9.jpg)
FUNCTION PROTOTYPE
It has the following parts1. Return type2. Function Name3. Parameters or Argument list
For e.g.:int sum ( int x, int y) ;
Return type
Name
Argument List
Function prototype must end with a semi
colon
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 10: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/10.jpg)
FUNCTION DEFINITION AND CALL#include<iostream. h> int square ( int n)#include<conio.h> {void main() return n x n;{ }
clrscr();int square(int);int a, s;cout<<“Enter value for a”;cin>>a;s = square(a);cout<<“Square of given no. is”<<s;getch();
}
S. Kiran PGT(Comp. Science), KV, Malleswaram
prototype
Func. call
Function definition
![Page 11: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/11.jpg)
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 12: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/12.jpg)
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 13: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/13.jpg)
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 14: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/14.jpg)
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 15: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/15.jpg)
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 16: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/16.jpg)
Note: A function prototype is not required if the function definition appears before its calling function
Program
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 17: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/17.jpg)
RECAPITULATION
S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 18: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/18.jpg)
Which feature of OOP does function exhibit?
List the advantages of using functions?
Name the different types of functions.
Three things to remember in a function ______
What does function prototype tell the compiler?
What is meant by return type?S. Kiran PGT(Comp. Science), KV, Malleswaram
![Page 19: What is a function? Functions are nothing but sub-programs of a program. Is a part of a program which performs a particular task as desired by the programmer](https://reader035.vdocuments.us/reader035/viewer/2022062905/5a4d1ad47f8b9ab059972691/html5/thumbnails/19.jpg)