In: Computer Science
Class object in C++ programming language description about lesson Overloading function example.
#include
#include
using namespace std;
//function overloading c++
// the same scope
int max(int a,int b) {
return (a
}
int max(int a,int b,int c) {
return (((a
}
double max(double a,double b) {
cout <<"calling double...."<
return (a
}
float max(float a,float b) {
cout <<"calling float...."<
return (a
}
void max(int *a,int n)
{
int mx=a[0];
for(int i=1;i
{
}
cout <<"max=" <
}
char *max( char *s1,char *s2)
{
if(strlen(s1)>strlen(s2)) return s1;
return s2;
}
int main()
{
cout <<"int max(10,-2)="<
cout <<"int max(200,10,1)="<
cout <<"double max(5.2,4.3)="<
cout <<"float max(5.2f,4.3f)="<
char *s1="hello c++", *s2="my c++ lang";
char *mx=max(s1,s2);
cout <<"char *max(\""<
int arr[]={4,-20,100,30,21};
int n=sizeof(arr)/sizeof(int);
for(int i=0;i
cout <
cout <<"==> max element: ";
max(arr,n);
}