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
Op e r a t o r O v e r l o a d i n g : W h e n   a n   o p e r a t o r   i s   u s e d   f o r   d i ff e r e n t   op e r a

Program to store family members details in C++: #include #include #include struct record {   char name[30];   int age;   char state[40]; }x; //cal

Define Functions with arguments and no return values The calling function will read a data from the terminal and pass it on to called as function and this will work good as the

Write a ‘C’ program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.

Program to print character array : Write a program to print the character array by using string class functions. void main() {  char line[30];   int i=0;   clrsc

How do you access the values within an array? - Arrays comprise a number of elements, which depends on the size you assigned it during variable declaration. - Every element

The concept of a string in C is difficult, because a string is a collection of characters stored in memory terminated by a NULL string i.e. \0. Let us consider the string Hello. Th

Write a simple generic version of method isEqualTo that compares its two arguments with the equals method and returns true if they are equal and false otherwise. Use this generic m


Explain about the Character Constants in c language? The character constant is a single alphabet and a single digit or a single special symbol enclosed within a pair of single