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 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
How long to learn object oriented programming?
What is super in oop?
What is a null tree?
What is polymorphism used for?
What is encapsulation in ict?
Why is polymorphism used?
What is abstract class in oop?
What is oops in simple words?
What is the real life example of polymorphism?
write knight tour problem which is present in datastructure
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
What is a class oop?
Why is abstraction used?
What is encapsulation example?