Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Inline function is the optimization technique used by the compilers.

One can simply prepend inline


keyword to function prototype to make a function inline. Inline function instruct compiler to insert
complete body of the function wherever that function got used in code.

Advantages :-

1) It does not require function calling overhead.

2) It also save overhead of variables push/pop on the stack, while function calling.

3) It also save overhead of return call from a function.

4) It increases locality of reference by utilizing instruction cache.

5) After in-lining compiler can also apply intraprocedural optmization if specified. This is the most
important one, in this way compiler can now focus on dead code elimination, can give more stress on
branch prediction, induction variable elimination etc..

"Overloading is the reuse of the same function name or symbol for two or more distinct functions or
operations"

Function overloading is the general concept of c++. A function can be declared more than once with
different operations. Function overloading means two or more functions can have the same name but
either the number of arguments or the data type of arguments has to be different. Return type has no
role because function will return a value when it is called and at compile time compiler will not be able
to determine which function to call. In the first example in our code we make two functions one for
adding two integers and other for adding two floats but they have same name and in the second
program we make two functions with identical names but pass them different number of arguments.
Function overloading is also known as compile time polymorphism.

C++ programming code for function overloading

#include <iostream>

using namespace std;

/* Number of arguments are different */

 
void display(char []); // print the string passed as argument

void display(char [], char []);

int main()

char first[] = "C programming";

char second[] = "C++ programming";

display(first);

display(first, second);

return 0;

void display(char s[])

cout << s << endl;

void display(char s[], char t[])

cout << s << endl << t << endl;

Output of program:

C programming

C programming

C++ programming
#include <iostream>  
  
using namespace std;   
int main()  
1. {  
2.  int a, b, c, m;  
 cout << "Enter the values of a, b and c: ";  
3.  cin >> a >> b >> c;  
4.  m = (b * b) - (4 * a * c);  
5.  if (m >= 0)  
6.  {  
7.   cout << "Roots are real" << endl;  
8.  }  
9.  else  
10.  {  
11.   cout << "Roots are imaginary" << endl;  
12.  }  
13.  return 0;  
  

You might also like