Inline Function in C++ in Hindi – इनलाइन फंक्शन क्या है?

Hello दोस्तों! आज हम इस post में Inline Function in C++ in Hindi (इनलाइन फंक्शन क्या है?) के बारें में पढेंगे और इसका example भी देखेंगे. इसे आप पूरा पढ़िए. आपको यह आसानी से समझ में आ जायेगा. तो चलिए शुरू करते हैं:-

Inline Function in C++ in Hindi

  • C++ में, Inline function एक महत्वपूर्ण concept है जिसका प्रयोग ज्यादातर class के साथ किया जाता है.
  • यदि एक फंक्शन inline होता है तो कम्पाइलर function के code की copy को function call के स्थान पर रखता है और इससे program का execution तेज हो सकता है.
  • C++ में, inline functions का प्रयोग करके function call के overhead को कम किया जाता है.
  • inline function को create करने के लिए inline कीवर्ड का प्रयोग किया जाता है.

inline function कैसे create करते हैं?

inline functions को create करने के लिए inline कीवर्ड का use किया जाता है. इसका syntax नीचे दिया गया है.

inline returnType functionName(parameters) {
    // code
}

Advantages of Inline function in C++ in Hindi – इसके लाभ

इसके लाभ निम्नलिखित होते हैं:-

  1. यह function call के overhead को कम देता है जिससे program का execution तेज होता है.
  2. जब function को call किया जाता है तो यह stack में push/pop variables के overhead को भी save करता है.
  3. यह एक function से return call के overhead को भी save करता है.
  4. इनलाइन फंक्शन embedded systems के लिए useful होता है.

Disadvantages of Inline Function in Hindi

इसकी हानियाँ निम्नलिखित हैं:-

  1. inline function के द्वारा variables की संख्या बढ़ जाती है. जिससे registers का utilization अधिक हो जाता है.
  2. अगर आप बहुत ज्यादा inline functions का प्रयोग करेंगे तो एक ही code का duplication हो जाता है. एक ही code का बार बार होना बहुत ख़राब होता है.
  3. inline functions का प्रयोग ज्यादा करने से instruction को fetch करने की speed भी कम हो जाती है.

Inline function का उदाहरण –

#include <iostream>
using namespace std;

inline int max_num(int x, int y) {
return (x > y)? x : y;
}

// Main function for the program
int main() {
cout << "Greater of ( 30, 40 ) is: " << max_num(30,40) << endl;
cout << "Greater of ( 100, 60 ) is: " << max_num(100,60) << endl;
cout << "Greater of ( -11, 46 ) is: " << max_num(-11,46) << endl;
return 0;
}

इसका आउटपुट –

Greater of (30, 40) is: 40
Greater of (100, 60) is: 100
Greater of (-11, 46) is: 46

ध्यान रखने वाली बात –

यहाँ ध्यान देने वाली बात यह है कि inlining कम्पाइलर के लिए एक request है, यह कोई command नहीं है. कम्पाइलर inlining की request को ignore भी कर सकता है. यह निम्नलिखित परिस्थितियों में inlining की request को ignore करता है:-

  1. यदि function में कोई loop होता है तो (जैसे:- for, while, do-while आदि).
  2. यदि function में static variables होते हैं.
  3. यदि फंक्शन recursive होता है.
  4. यदि function में switch command या goto statement होता है.

references :-

inline function in c++ in hindi

निवेदन:- अगर आपके लिए यह article उपयोगी रहा हो तो इसे अपने friends और classmates के साथ अवश्य share कीजिये. और आपके इससे related कोई सवाल हो तो उसे नीचे comment करके बताइए.

अगर आपका कोई suggestion है या किसी अन्य subject से सम्बन्धित कोई सवाल हो तो उसे भी कमेंट करके बता सकते हैं. धन्यवाद.

Leave a Comment