Write a program of inline function, C/C++ Programming

Assignment Help:

Here is a program that uses an inline function to compute and return the absolute value of its input argument.

# include

inline int abs(int x)

{

                 return x <0? -x : x ;

}

void main( )

                {

                  for (int i=-2 ; i<2 ; ++i)

                   {

           int value = abs(i) ;

           printf ("Absolute value of %+d = %+d\n",i, value);

         } 

      }

The output is:

Absolute value of -2 =+2

Absolute value of -1 =+1

Absolute value of +0 =+0

Absolute value of +1 =+1

When the call to the abs ( )  function is encountered, the compiler, instead of making a function call, generates this assembly code.

 


Related Discussions:- Write a program of inline function

C program to maintain database of employees, Aim: To implement a program t...

Aim: To implement a program to maintain information of employees in an educational institute using inheritance. Code:                       class staff {

Using functions create a program, In rPeANUt implement the "char getchar()"...

In rPeANUt implement the "char getchar()" and "void printstring(char *str)" functions. Using these functions implement the following: void main() {    while (1) {       ch

.., write a c++ code to implement use of a constructor

write a c++ code to implement use of a constructor

Explain static member functions, Static Member Functions All the object...

Static Member Functions All the objects of the class share static data members of a class. The example above demonstrates how to keep track of all the objects of a class which

Random question, Ask question #write statement that assign random integer t...

Ask question #write statement that assign random integer to the varaible n in the (100

Program for construct a struct - user defined data type, Define a user-defi...

Define a user-defined data type (struct) called Car to represent a car in the context of a car dealership database. Car must have at least the following characteristics: Make Model

State six typical application of primary cells, Normal 0 false ...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

Oops, write a c++ program to find the prime numbers

write a c++ program to find the prime numbers

When i develop a destructor, When I develop a destructor, do I require to e...

When I develop a destructor, do I require to explicitly call the destructors for my member objects?

Decode the code, smugglers are becoming very smart day by day. Now they hav...

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 technology, they are send

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