What is c++ inline function in hindi-c++ इन्लिने फंक्शन क्या है?

हेल्लो दोस्तों आज के इस पोस्ट में आपको c++ inline function in hindi के बारे में बताया गया है की इसे कैसे प्रयोग करते है तो चलिए शुरू करते है

c++ inline functions का परिचय

जब program किसी normal function को execute करता है तो सबसे पहले CPU function को call statement के बाद वाले statement का मेमोरी address को store करता है ऐसा इसलिए किया जाता है ताकि function के execute होने के बाद इस statement से execution को शुरू किया जा सके

इसके बाद compiler arguments को stack में copy करता है इसके बाद control function को transfer हो जाता है इसके बाद CPU function को code को execute करता है और return value को regiser में store करता है इसके बाद control को वापस function को calling statement को चला जाता है

जब किसी भी function का calling time उसके execution time से अधिक होता है तो उसे overhead माना जाता है calling time वह time होता है जो cpu को function call और function execution के बीच लगता है

क्योकि cpu एक मेमोरी location से दूसरी मेमोरी लोकेशन पर switch करता है और उसके बाद function को execute करता है और फिर उसके बाद वापस actual location पर return करता है इस process में काफी अधिक समय लग जाता है

बड़े function जिनको execute होने से अधिक समय लगता है उसके लिए इस time को appropriate माना जा सकता है लेकिन छोटे function जो बहुत कम समय में execute हो जाते है उसके लिए एक मेमोरी location से दूसरी मेमोरी location में switch होने का time waste करना appropriate नहीं होता है

हालाकि हो सकता है की अभी ये time आपको महत्वपूर्ण न लगे लेकिन जब बात बड़े projects की आती है तो execution time को reduce करना एक priority होती है

इस situation में छोटे functions के द्वारा waste किये जा रहे function को calling time  को save करने के लिए c++ आपको एक mechanism प्रोविडे करती है जिसे inline function कहते है

inline function c++ में एक important feature है जब आप किसी भी function को inline को define करते है तो उस function को execute करने के लिए compiler मेमोरी location switch नहीं करता है इसके बजाय compiler calling statement को function को definition से replace कर देता है ये काम compiler के द्वारा compile time पर किया जाता है

एक बात आपको ध्यान रखने योग्य है की जब आप किसी function को inline define करते है तो ये compiler के लिए सिर्फ एक request होती है जरुरी नहीं की compiler इस function को inline करे compiler इसे ignore भी कर सकती है

यदि किसी function में loop होता है तो static variable होते है switch और goto statement होते है या फिर यदि function recursive होता है तो ऐसी situation में compiler function को inline नहीं करता है

जब आपको program की efficiency बढ़ाने की आवश्यकता हो तो आप inline function को प्रयोग कर सकते है macros के साथ आने वाली problems को eliminate करने के लिए भी inline functions को प्रयोग किया जाता है

advantage of inline functions

निचे inline functions को कुछ advantage दी जा रहि है

  1. क्योकि function call को function definition से replace कर दिया जाता है इसलिए function को call का overhead नहीं होता है
  2. argument variables को stack में store करने का overhead भी inline function को प्रयोग करने से remove हो जाता है
  3. inline function के प्रयोग से function के वापस return होने का overhead भी नहीं होता है

disadvantage of inline functions

निचे inline function की कुछ disadvantage दि जा रही है

  1. inline function का प्रयोग करने से program को बड़ा हो जाता है और executable file की size बढ़ जाती है
  2. क्योकि function को compile time पर inline किया जाता है इसलिए यदि आप किसी inline function के code को change करने है तो आपको उन सभी programs को भी recompile करना होगा जो की इस function को प्रयोग कर रहे है
  3. जब आप inline function को header में प्रयोग करते है तो इससे आपकी header file बड़ी हो जाती है
  4. जैसा की पहले बताया गया inline function का प्रयोग करने से executable file की size भी बढ़ जाती है ऐसा होने से इस executable file के लिए अधिक मेमोरी की आवश्यकता पड़ती है आवश्यकता से कम मेमोरी होने पर program की efficiency पर फर्क पड़ता है

syntax & example of inline functions

inline function का जनरल syntax आपको निचे दिया जा रहा है

inline return_type function_name(parameter list)
{
      //function body
}

जैसा की आप  उपर दिए गए syntax में देख सकते है की function को inline बनाने के लिए उसकी normal definition से पूर्व inline keyword का प्रयोग किया गया है

तो आएये अब inline function के प्रयोग को एक example के माध्यम से समझते का प्रयास करते है

#include<iostream>
Using namespace std;
Inline int add(int x,int y)
{
      Return x+y;
}
Int main()
{
     Int a,b;
        Cout<<”please enter first number:”;
        Cin>>a
         Cout<<”please enter second number:”;
         Cin>>b;
         Cout<<endl;
         Cout<<”sum of a & b is:”<<add(a,b);
        Return 0;
}

उपर दिए गए program में निचे दिया गया आउटपुट को generate करता है

please enter first  number
9
please enter second number
8
sum of a & b:17

c++ inline function in hindi

reference-https://www.geeksforgeeks.org/inline-functions-cpp/

निवेदन:-आप सभी छात्र –छात्रों से निवेदन है की अगर आपको ये Topic(c++ inline function in hindi) अच्छा लगा हो तो कृपया आप इस वेबसाइट के बारे में अपने दोस्तों को जरुर बताये अगर कोई topic(c++ inline function in hindi) से संबधित प्रश्न हो तो कमेंट्स(comments) आपके लिए ही बना है और किसी Subject(c++ inline function in hindi) के लेकर भी कोई प्रश्न हो तो कमेंट करे

Leave a Comment