CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies

Search Interview Questions

Question: What do you mean by inline function?

Answer: 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.



Category Functions in C++ Interview Questions & Answers - Exam Mode / Learning Mode
Rating (4.0) By 81 users
Added on 10/22/2009
Views 12592
Rate it!
Question: What do you mean by inline function?
Answer:

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. Source: CoolInterview.com


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> Source: CoolInterview.com

Answered by: Anitha | Date: | 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> Source: CoolInterview.com

Answered by: Anitha | Date: | 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> Source: CoolInterview.com

Answered by: uday | Date: | 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. Source: CoolInterview.com

Answered by: ambarish | Date: 1/30/2009 | Contact ambarish Contact ambarish

inline fuctions reduce the excution time,it wont accept long statements Source: CoolInterview.com

Answered by: umapathi | Date: 4/30/2009 | 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. Source: CoolInterview.com

Answered by: Dilip | Date: 7/20/2009 | 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 Source: CoolInterview.com

Answered by: sistla laxmi | Date: 8/20/2009 | 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> Source: CoolInterview.com

Answered by: poonam yadav | Date: 8/23/2009 | 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>} Source: CoolInterview.com

Answered by: RajeshKumar | Date: 8/31/2009 | 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. Source: CoolInterview.com

Answered by: Anthony | Date: 9/25/2009 | 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. Source: CoolInterview.com

Answered by: Pratibha Bharti | Date: 10/18/2009 | 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. Source: CoolInterview.com

Answered by: T.Ravi Kumar | Date: 11/21/2009 | 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> Source: CoolInterview.com

Answered by: Monalisha Nayak | Date: 12/17/2009 | 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 Source: CoolInterview.com

Answered by: pavan kumar | Date: 12/30/2009 | 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. Source: CoolInterview.com

Answered by: prasad | Date: 1/17/2010 | 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........ Source: CoolInterview.com

Answered by: Prakash | Date: 6/27/2010 | 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. Source: CoolInterview.com

Answered by: kumar gourav | Date: 7/6/2010 | Contact kumar gourav Contact kumar gourav


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.

Post your answer here

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 & Answers - Exam Mode / Learning Mode




India News Network
Latest 20 Questions
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
"Holiday Packages" announced as an advertisement are an example of _________: (a) Offer (b) Counter Offer (c) Invitation to Offer (d) None of the above
A match fixing contract between a player and a broker is a: (a) Valid Contract (b) Unenforceable Contract (c) Void Contract (d) Illegal Contract
When a bookseller sells a book on cash payment then it is called as ___________: (a) Unilateral Contract (b) Bilateral Contract (c) Executed Contract (d) Executory Contract
____________ agreements are created by situation: (a) Written (b) Oral (c) Void (d) Implied
Cache = 0.03125 Seconds