Posts

Showing posts with the label Inline Functions

Inline Functions in C++ - Inline Functions vs Macros with Examples

An inline function is a function in C++ that is declared using the inline keyword. It suggests to the compiler that the function's code may be substituted directly at the point where the function is called, potentially reducing function call overhead. The compiler is not required to follow this suggestion. It decides whether to expand the function inline based on its optimization strategy. Inline Function C++ का एक ऐसा Function होता है जिसे inline Keyword का उपयोग करके Declare किया जाता है। यह Compiler को सुझाव देता है कि Function Call के स्थान पर Function का Code सीधे रखा जा सकता है। इससे कुछ परिस्थितियों में Function Call का Overhead कम हो सकता है। Compiler के लिए इस सुझाव को मानना अनिवार्य नहीं है। वह अपनी Optimization Strategy के अनुसार तय करता है कि Function को Inline करना है या नहीं। Syntax of Inline Function – Inline Function का सिंटैक्स inline return_type function_name(parameters) { // Statements } Example: inline int square(int n) { return n * n; } Here, inline ...