0% found this document useful (0 votes)
24 views7 pages

Lecture 4

Functions allow code to be reused by performing specific tasks and taking in parameters. There are different types of functions including built-in and user-defined functions. Functions can take in arrays and parameters. Function overloading allows multiple functions to have the same name but different signatures by varying the number, order, or type of parameters. Local and global variables also impact functions.

Uploaded by

Ayesha Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

Lecture 4

Functions allow code to be reused by performing specific tasks and taking in parameters. There are different types of functions including built-in and user-defined functions. Functions can take in arrays and parameters. Function overloading allows multiple functions to have the same name but different signatures by varying the number, order, or type of parameters. Local and global variables also impact functions.

Uploaded by

Ayesha Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 7

CS-212

OBJECT ORIENTED
PROGRAMMING
MEHREEN TAHIR
Functions
• Perform specific task
• Reusability
Functions
• Prototype
• Definition
• Call
Functions
• Local and global variables
• Built in functions
• User defined functions
Functions
• Passing arrays to functions
• Function overloading
• Function signature
– A function's signature includes the function's name and
the number, order and type of its formal parameters.
– Two overloaded functions must not have the same
signature.
– The return value is not part of a function's signature.
Functions
• int Divide (int n, int m)
• double Divide (int n, int m)
• float Divide (int x, int y)

• Make overloaded functions of sum


Functions
int sum(int x[],int y){ //how about int sum(int x[5])
std::cout<<"size of x= "<<sizeof(x);
for (int i=0;i<y;i++){ // for (int i=0;i<5;i++){
std::cout<<"array="<<x[i];}
return 0;}
void main(){
int a[5]={31,32,33,34,35};
std::cout<<"size of a= "<<sizeof(a)/sizeof(a[0]);
sum(a,5); }

You might also like