-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16inline_defaultarg.cpp
More file actions
25 lines (24 loc) · 1.05 KB
/
Copy path16inline_defaultarg.cpp
File metadata and controls
25 lines (24 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
using namespace std;
inline int product(int a, int b) //inline is only used for easy and simple functions otherwise they would take a lot of memory
{
return a*b;
}
float moneyReceived(float money, float rate = 1.04) //this is a default argument where there is already a value for 'rate'
{
return money * rate; //default arguments should be written in the end to avoid mixing when calling the function
}
int main()
{
int a, b;
cout<<"The value of a is "<<endl;
cin>>a;
cout<<"The value of b is "<<endl;
cin>>b;
cout<<"The product of a and b is "<<product(a, b)<<endl; //using inline, if this simple function is repeated multiple times, the compile time is even faster
float money = 100000;
cout<<"The money "<<money<<" rs will be converted to "<<moneyReceived(money)<<" rs after interest"<<endl;
cout<<"The money "<<money<<" rs will be converted to "<<moneyReceived(money, 1.1)<<" rs after interest"<<endl;
//here, in the function call a value is provided to rate which replaces the default value
return 0;
}