write a c++ program to find maximum of two numbers using
inline functions.

Answer Posted / ada

#include <iostream>
using namespace std;

template<typename T>
inline T& max(T& x, T& y)
{
return x>y ? x:y;
}

int main()
{
char bx = 'a', by = 'b';
int ix = 1, iy = 2;
float fx = 1.5, fy = 2.5;
double dx = 2.5, dy = 1.5;
cout<<"char max:"<<max(bx, by)<<endl;
cout<<"int max:"<<max(ix, iy)<<endl;
cout<<"float max:"<<max(fx, fy)<<endl;
cout<<"double max:"<<max(dx, dy)<<endl;
return 0;
}

Is This Answer Correct ?    39 Yes 33 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to call a non virtual function in the derived class by using base class pointer

5964


What is super in oop?

873


2. Give the different notations for the class.\

1837


i got a backdoor offer in process global,Bangalore..Can i work with it?

2597


Why polymorphism is used in oops?

811


What is the difference between static polymorphism and dynamic polymorphism?

870


Write a c++ program to display pass and fail for three student using static member function

3114


Advantage and disadvantage of routing in telecom sector

1056


Why is static class not inherited?

851


explain sub-type and sub class? atleast u have differ it into 4 points?

2060


hi all..i want to know oops concepts clearly can any1 explain??

1905


When not to use object oriented programming?

800


What is polymorphism and types?

867


What is encapsulation in ict?

831


What is pointer in oop?

748