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
C++ improves on many of C's features and provides object-oriented programming capabilities used for software production, quality and reusability. C++ was developed by Bjarne Strons

Constructors and Destructors: A Class is defined as constructor by declaring a constructor in the form of function inside the class.  In other word a function in the name of

wap to calculatethe volume of cone,cylinderand sphere

Problem : Change to palindrome A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your ta

#questAt a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets wit

void main() { int *p, *q, i ; p=(int*)100; q=(int*)200; i=q-p; printf("%d",i); } }

Insertion sort - C program: Write a program in c to define a insertion sort. void main()  {   clrscr();   int a[100],ch,n;   cout   cin>>n;   for (int i=0

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

Project Description: I am seeking someone who can make this modem work with Linux Caller ID on Ubuntu present stable version. Skills required are C Programming, Python