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
What is class encapsulation?
How to call a non virtual function in the derived class by using base class pointer
i=20;k=0;
for(j=1;k-i;k+=j<10?4:3)
{
cout< What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems? What is object and example? What is the advantage of oop over procedural language? What are the 4 main oop principles? What is the real time example of inheritance? What is meant by multiple inheritance? What do you mean by variable? What is polymorphism oop? what type of question are asked in thoughtworks pair programming round ? class CTest
{
public:
void someMethod()
{
int nCount = 0;
cout << "This is some method --> " << nCount;
}
};
int main()
{
CTest *pctest;
pctest->someMethod();
return 0;
}
It will executes the someMethod() and displays the value
too. how is it possible with our creating memory for the
class . i think iam not creating object for the class.
Thanks in Advance...
Prakash Why is abstraction used? hi all..i want to know oops concepts clearly can any1
explain??