Inline functions, C/C++ Programming

Assignment Help:

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);
 }


Related Discussions:- Inline functions

Explain automatic variables, Automatic Variables Automatic variables ar...

Automatic Variables Automatic variables are variable which are explained within the functions. They lose their value when the function terminates. It can be accessed only in th

Determine the canonical form, Rule: To determine the canonical form we s...

Rule: To determine the canonical form we should OR the min terms. A min term is defined as a Boolean equation of the input if the output is logic '1'. If the input is logic '1'

Briefly describe how a linear search algorithm works, Question 1: (a) D...

Question 1: (a) Describe the following objects and condition states: (i) ifstream and ofstream objects (ii) eof(), fail(), bad() and good() functions. (b) Write a C++ pr

Padovan string, A Padovan string P(n) for a natural number n is defined as:...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concate program 1 : package test

Should my class declare a friend function or member function, A: Use a memb...

A: Use a member while you can and a friend when you need to. Sometimes friends are better syntactically (e.g., in class Fred, friend functions let the Fred parameter to be secon

Algorithm, algorithm to prepare mark sheet of a student by inputing name,br...

algorithm to prepare mark sheet of a student by inputing name,branchcode,semester,register no,5 marks of students and total mark of student

C++, Write a program to find the area under the curve y = f(x) between x = ...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Some of the basic rules of cpp program, Ba s i c r u l e s o f C...

Ba s i c r u l e s o f C + + p r o g r a m : ·     I t m u s t h a v e o n l y o n e m a i n f u n c ti o n ·

Prepare windows shell extension, Prepare Windows Shell Extension Project...

Prepare Windows Shell Extension Project Description: Skills required are C++ Programming, Windows Desktop, Windows API

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd