write a c++ program to find maximum of two numbers using
inline functions.
Answers were Sorted based on User's Feedback
#include<iostream>
using namespace std;
int main()
{
int c;
c=max(5,4); //will display 5
cout<<c<<endl;
return 0;
}
inline int max(int a, int b)
{
return (a>b)? a:b;
}
| Is This Answer Correct ? | 140 Yes | 52 No |
Answer / 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 |
why c++ is a highlevel language
3 Answers Satyam, Tech Mahindra,
What is inheritance and how many types of inheritance?
What is difference between class and object with example?
How oops is better than procedural?
hi all..i want to know oops concepts clearly can any1 explain??
Can you inherit a private class?
Why is object oriented programming so hard?
what is the main difference between sizeof() operator in c and c++
Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference between interfaces and abstract class?
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }
Should you protect the global data in threads? Why or why not?
some one give d clear explanation for polymorphism