Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added inline functions and examples #79

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions C++/inline_functions_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
using namespace std;
/*When we call functions the exceution of main function stops for a while and program waits for result.
This causes undesirable waste of time. One solution is to use tertiary operator wherever possible rather than using functions, which makes execution of program fast.
However writing more and more tertiary operators would make our code look overwelming at some point of time.
To avail both clean code and fast speed ,C++ has a powerful concept of inline functions(which are not true functions but part of main block itself).
At the tijme of compiling the compiler would itself place the inline code where the function has been called
in our main function. Hence we have achieved fast execution as well as clean code
Further Reading : https://www.geeksforgeeks.org/inline-functions-cpp/
*/
inline int max(int a,int b){
return (a>b?a:b);
}
inline int min(int a,int b){
return (a<b?a:b);
}
int main() {
int a,b;
cout << "Enter the numbers: ";
cin >> a >> b;
int ans = max(a,b);
cout << ans;
return 0;
}