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

Program Preprocessor variable postfix , Run the following C++ program with ...

Run the following C++ program with and without preprocessor variable POSTFIX defined. #include using namespace std; extern "C" int atoi( const char *str );

Mini Search Engine, How do I create two functions: one to put a collection ...

How do I create two functions: one to put a collection of criteria into normal form, and one to compute the score of a document. A collection of criteria will be represented using

C program for function of average, C program for function  of average ...

C program for function  of average int average(int); void main() {           int max=0,c=0;           clrscr();           printf("ENTER THE LIMIT OF INPUT FOR AV

C expressions - assume variables are double or float, Assume variables x, f...

Assume variables x, f, and d are of type int, float, and double, respectively.  Their values are arbitrary, except that neither f nor d equals +∞, -∞, or NaN .  For each of the fo

Super ASCII String Cost, A string S is said to be "Super ASCII", if it cont...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Academic expert for genetic algorithm, Academic expert for Genetic Algorith...

Academic expert for Genetic Algorithm Project Description: Seeking academic expert for Genetic Algorithm. Skills required are Academic Writing, Algorithm, C++ Programming,

#decode the code, #Smugglers are becoming very smart day by day. Now they h...

#Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new techn

Work related, Make the following 3 functions work by filling in appropriate...

Make the following 3 functions work by filling in appropriate C code. This file 1. // Write a function to count the number of particular characters in a string. // Do not use a

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