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
Why is abstraction used?
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?
State what is encapsulation and friend function?
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).
How to use CMutex, CSemaphore in VC++ MFC
Which is not an object oriented programming language?
Why do we use encapsulation in oops?
Why do we use oop?
What is abstraction encapsulation?
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
What is oops and its features?
what's the basic's in dot net
What is methods in oop?
to find out the minimum of two integer number of two different classes using friend function
Explain the concepts involved in Object Oriented programming.