Inline Function
Inline Function
CODE:
#include<iostream>
using namespace std;
inline int sum(int x,int y)
{
return (x+y);
}
inline int sub(int x,int y)
{
return (x-y);
}
inline int mul(int x,int y)
{
return (x*y);
}
int main()
{
cout << "W.A.P to perform addition, subtraction and multiplication using inline function.\n\n\n";
int a,b,CHOICE;
cout << "ENTER THE VALUE OF A & B" << endl;
cin >> a >> b;
cout << "1. SUM" << endl << "2. SUBTRACTION" << endl << "3. MULTIPLICATION" << endl;
cin >> CHOICE;
switch(CHOICE)
{
case 1:
sum(a,b);
cout << "SUM = " << sum(a,b) << endl;
break;
case 2:
sub(a,b);
cout << "SUBTRACTION = " << sub(a,b) << endl;
break;
case 3:
mul(a,b);
cout << "MULTIPLICATION = " << mul(a,b) << endl;
break;
default:
cout << "CHOICE IS WRONG";
}
}
OUTPUT:
- Inline function is important concept of c++
- If we define function with keyword "inline" compiler copies the code during compilation.
- Inline function is define with keyword "inline"
CODE:
#include<iostream>
using namespace std;
inline int sum(int x,int y)
{
return (x+y);
}
inline int sub(int x,int y)
{
return (x-y);
}
inline int mul(int x,int y)
{
return (x*y);
}
int main()
{
cout << "W.A.P to perform addition, subtraction and multiplication using inline function.\n\n\n";
int a,b,CHOICE;
cout << "ENTER THE VALUE OF A & B" << endl;
cin >> a >> b;
cout << "1. SUM" << endl << "2. SUBTRACTION" << endl << "3. MULTIPLICATION" << endl;
cin >> CHOICE;
switch(CHOICE)
{
case 1:
sum(a,b);
cout << "SUM = " << sum(a,b) << endl;
break;
case 2:
sub(a,b);
cout << "SUBTRACTION = " << sub(a,b) << endl;
break;
case 3:
mul(a,b);
cout << "MULTIPLICATION = " << mul(a,b) << endl;
break;
default:
cout << "CHOICE IS WRONG";
}
}
OUTPUT:
0 Comments