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

Creates and implements a class to represent the queue, Purpose This ass...

Purpose This assignment is an exercise in implementing the queue ADT using a singly-linked list. This assignment also introduces the concept of templates. Assignment Th

Vb.net, write a program that would accept the radius of the sphere and retu...

write a program that would accept the radius of the sphere and return its surface area.

C++, Byteland county is very famous for luminous jewels. Luminous jewels ar...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Write a function that takes in radius and cover screen, Write a function th...

Write a function that takes in a radius and evenly covers the screen with circles of that radius. Don't attempt to draw any circles that are completely off the screen.

Define procedure to input integers and returns the average, The procedure +...

The procedure +, * and list take arbitrary numbers of arguments. One way to define such a procedure is to use define with dotted-tail notation. In a procedure definition, a paramet

Area under curve, Write a program to find the area under the curve y = f(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

Change to palindrome, A palindrome is a string that reads the same from bot...

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 task is to convert S to palindrome

Pointer, solution of problem based on poiter

solution of problem based on poiter

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