Inline functions, C/C++ Programming

Inline functions, C++ provides inline functions to help reduce function_call overhead especially for small functions. The

qualifier inline before function's return type in the function informs the computer to generate a copy of the functions code in place, to avoid a function call.

The disadvantage is that multiple copies of function code are inserted in the program (thus making it larger) rather than a single copy of the function to which control is passed each time the function is called.
The compiler can ignore the inline qualifier especially for large functions

Example:

Write a C++ program that prompts for the radius of a circle, and which is passed to an inline function to compute and return the area of a circle. Your program then displays the computed value.

#include 

#include 
#include 
using namespace std;

inline double computearea(int);
int main()

{

int radius; 

double area;

cout<<"Enter the radius of the circle"<>radius;

area=computearea(radius);

cout<<"The area of the circle is:"

<return  0;

}

double computearea(int r)
{

const float    PI=3.142;
     
return PI*pow(r,2);
 }

Posted Date: 8/21/2012 11:50:25 AM | Location : United States







Related Discussions:- Inline functions, Assignment Help, Ask Question on Inline functions, Get Answer, Expert's Help, Inline functions Discussions

Write discussion on Inline functions
Your posts are moderated
Related Questions
A: you can exploit by overloading standard operators on a class, the intuition of the users of that class. This allow users program in the language of the problem domain instead of

There are ''''n'''' ants on a ''''n+1'''' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are mov

Implement multiple stacks in a single dimensional array using c.

i need to do my home work

accept principal amount,rate of interest, & duration from the user. display interest amount and total amount

Explain the Bitwise-Inclusive-OR Operator: |? The bitwise-inclusive-OR operator (|) contrast each bit of its first operand to the corresponding bit of its second operand and if

I need help to understand and do this assignment ********************************************************* You are to insert the missing code in the C program given for combinatio


#include stdio.h   struct  complex   {   float real;   float imag;   };   struct complex complexadd(struct complex,struct  complex);   void main()     {          Date: 26

C Program for MAXIMUM NO, MINIMUM NO AND SORTING   void main() {           int i,j,t;           int a[5];           clrscr();           for(i=0;i