CoolInterview.com - World's Largest Collection of Interview Questions
Start Your Own website Now
Sponsored Links

Interview Questions
Our Services

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies


  • INTERVIEW QUESTIONS C++ FUNCTIONS IN C++ DETAILS
    Question :
    What do you mean by inline function?
    Category Functions in C++ Interview Questions
    Rating (0.4) By 1469 users
    Added on 10/22/2004
    Views 13990
    Rate it!
    Answers:

    The idea behind inline functions is to insert the code of a called function at the point where the<br>function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.



    Inline functions are like macros in c language. The functions are expanded in the line where it is invoked at the time of compilation. These functions should not include any loops or static members inside it. And also it shouldn?t be a recursive one. Inline functions should return a value .The advantages are to avoid time wastages , stack and registers operations done during function calls and function invokations. Keyword ?inline? should be included in the function definition.<br><br>Example:<br> inline int add(int a,int b)<br> {<br> return a+b;<br> }<br><br> void main()<br> {<br> int x=5;<br> int y=10;<br> cout<<?The sum is : ?<<add(x,y);<br> }<br><br>



    Posted by: Anitha    

    Contact Anitha Contact Anitha

    Inline functions are like macros in c language. The functions are expanded in the line where it is invoked at the time of compilation. These functions should not include any loops or static members inside it. And also it shouldn?t be a recursive one. Inline functions should return a value .The advantages are to avoid time wastages , stack and registers operations done in memory during function calls and function invokations. Keyword ?inline? should be included in the function definition.<br><br>Example:<br> inline int add(int a,int b)<br> {<br> return a+b;<br> }<br><br> void main()<br> {<br> int x=5;<br> int y=10;<br> cout<<?The sum is : ?<<add(x,y);<br> }<br>



    Posted by: Anitha    

    Contact Anitha Contact Anitha

    inline function is function,the complier insert the entire code where the function is called.<br>inline fuctions reduce the excution time,But it can be used for only smaller functions.<br>



    Posted by: uday    

    Contact uday Contact uday

    Inline function is declared to a function so cpp automatically creats its own programme which is unvisible to us.so this function reduces the compile time.but it not suitable for using for loop.Becouse it creats more line prg. than actual prg.



    Posted by: ambarish    

    Contact ambarish Contact ambarish

    inline fuctions reduce the excution time,it wont accept long statements



    Posted by: umapathi    

    Contact umapathi Contact umapathi

    Inline function makes a program run faster bcoz the overhead of a function call and return is eliminated. This replaced at each point where the function is called.



    Posted by: Dilip    

    Contact Dilip Contact Dilip

    inline functions are used to overcome the overhead [the flow of control] of the functions. If a function is defined in the class then by default it acts like an inline function. If a function is defined outside the class, explicitly we need to specify inline keyword. Inline function is very similar to a macro in C



    Posted by: sistla laxmi    

    Contact sistla laxmi Contact sistla laxmi

    Inline function are like as macro but they r not macro,when we have to do call a function many times n as our program is small,it takes more execution time,dn for saving the times we use the inline function,it saves our execution times but it doesnot ter approach in large prorame,for using inline function we have to write simply inline before our functon,they have regular wriiten type,<br>e.g<br> inline int sum(int x,int y)<br> {<br> sum=x+y;<br> }<br> void main()<br> int x=2;<br> int y=4;<br>cout<<"
    result is:"<<sum(x+y);<br>}<br>



    Posted by: poonam yadav    

    Contact poonam yadav Contact poonam yadav

    Inline function to speed up the execution of the program...<br>Syn:<br>inline type fnname()<br>{<br>....<br>....<br>}



    Posted by: RajeshKumar    

    Contact RajeshKumar Contact RajeshKumar

    inline function is like macros in c language. It expands code for a called function which reduces execution time and inline function provides type safety which macros don't provide.



    Posted by: Anthony    

    Contact Anthony Contact Anthony

    Inline function are just like Macros with some differance<br><br>1. Inline function is a function whereas macros are preprocessive directories.<br><br>2. inline function put request to compiler not command hence if the size of inline functions ihncreases compiler ignore the request & treates the inline function like normal function.



    Posted by: Pratibha Bharti    

    Contact Pratibha Bharti Contact Pratibha Bharti

    Inserting inline function is completely depends on the compiler, because we are just request to the compiler to perform inline function. Its depends on the function definition thats why it should be small lines of code. After using this function we are not sure this function will insert or not.



    Posted by: T.Ravi Kumar    

    Contact T.Ravi Kumar Contact T.Ravi Kumar

    The function whose code gets inserted, instead of a jump to the function, at the place of call, is called an inline function. Inline functions mayn't work for functions returning values, if a loop or switch or goto exists or if they are recursive.<br><br>Inline functions speed up processing by eliminating the overhead associated with function calls.<br><br>These inline functions help in improving overall performance, but sometimes they make it worse.<br><br>It is a good practice to define functions inline when they are on the critical path of a CPU-bound application. But if the application is network or I/O bound there will be no significant impact.<br><br>



    Posted by: Monalisha Nayak    

    Contact Monalisha Nayak Contact Monalisha Nayak

    when a function is called it takes lot of time to executed more no.of instructions so we are using inline function <br> Inline function is a function that is expanded inline when that is invoked.compiler replaces function call to the code



    Posted by: pavan kumar     

    Contact pavan kumar Contact pavan kumar

    inline function provides an efficient way for the compiler with the regards of compile time because;it EXPANDS the called function (for example a subfunction being called in the main program)and hence prevents compiler to jump to the location where exactly the function has been DEFINED. Hence by reducing the number of jumps it reduces the overall compile time.



    Posted by: prasad    

    Contact prasad Contact prasad

    when a function is invoked so many times, the compiler pushes those function parameters and its code to stack and allocating registers to that... This is better at the level for bigger function....<br> But what about for smaller function(i.e. not containing loops and only few lines)....now a answer arises....s correct.....its waste of time.... <br> C++ avoids this waste of time and resources by providing a greater mechanism called "INLINE FUNCTIONS" .<br> When a function s declared as inline function, the compiler understands that invoked function s so small so it just replaces code instead of pushing parameter into the stack like MACRO.....and then execution begins........



    Posted by: Prakash    

    Contact Prakash Contact Prakash

    A common practice is to omit the prototype and to place the entire definition (meaning the function header and all the function code) where the prototype would normally go. The compiler does not have to honor your request to make a function inline. It might decide the function is too large or notice that it calls itself (recursion is not allowed or indeed possible for inline functions), or the feature might not be turned on or implemented for your particular compiler.



    Posted by: kumar gourav    

    Contact kumar gourav Contact kumar gourav

    when inline function as declared,the compiler copies of code placed in its function caller.



    Posted by: veeru    

    Contact veeru Contact veeru

    when inline function as declared,the compiler copies of code placed in its function caller.



    Posted by: veeru    

    Contact veeru Contact veeru

    function means a set of executable statements to complete a specified task by any no.of times as per user requriment.we can just call it by passing appropriate arguments



    Posted by: g.venkata ramana    

    Contact g.venkata ramana Contact g.venkata ramana

    the inline function is mainly used for provide declaration and defination of any function in a single line only by using the inline kew word infront of the function name.

    like as-inline Add(int a ,int b)
    {
    return a*b;
    }



    Posted by: Renu joshi    

    Contact Renu joshi Contact Renu joshi

    If you have the better answer, then send it to us. We will display your answer after the approval.
    Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       
    Related Questions
    View Answer


    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL Functions in C++ Interview Questions

    User Options
    Sponsored Links


    Copyright ©2003-2014 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes


    Cache = 0.015625 Seconds