by Dinesh Thakur Category: Function and Pointer

The qualifier inline has been introduced in C-99 in order to achieve better compatibility between C and C++. If a small function needs to be called a large number of times in a program, the overburden of function call can make the program inefficient. Also, if the function code is put in the listing of the program wherever it is needed, it will not only make the program lengthy but also clumsy. With qualifier inline we need to define the function only once and the compiler substitutes the code wherever the function is called in the program. This eliminates the multiple function call as well as the drudgery of typing the function code a large number of times in the program. Thus, the qualifier inline makes a program efficient and also lessens the work of the programmer. An illustration of its application is illustrated below.

inline int Function(int x)

{return x*x;}

The same effect may also be achieved in C language by defining the above function as a macro. The following macro is equivalent to the above inline function. A disadvantage of a macro is that there is no type checking.

#define Function(x) (x)*(x)



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles