From 148b388757b573a06028fb9c8062426730cb9c89 Mon Sep 17 00:00:00 2001 From: Vibhu NIT waale <80385154+Joaquin144@users.noreply.github.com> Date: Mon, 25 Oct 2021 10:35:40 +0530 Subject: [PATCH] Added inline functions and examples --- C++/inline_functions_example.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 C++/inline_functions_example.cpp diff --git a/C++/inline_functions_example.cpp b/C++/inline_functions_example.cpp new file mode 100644 index 0000000..5560db2 --- /dev/null +++ b/C++/inline_functions_example.cpp @@ -0,0 +1,24 @@ +#include +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> a >> b; + int ans = max(a,b); + cout << ans; + return 0; +}