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

Why is abstraction used?

608


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

2759


State what is encapsulation and friend function?

699


write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).

1642


How to use CMutex, CSemaphore in VC++ MFC

4332






Which is not an object oriented programming language?

544


Why do we use encapsulation in oops?

522


Why do we use oop?

605


What is abstraction encapsulation?

657


Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer

1621


What is oops and its features?

587


what's the basic's in dot net

1739


What is methods in oop?

542


to find out the minimum of two integer number of two different classes using friend function

1642


Explain the concepts involved in Object Oriented programming.

638