Jul 31, 2013 at 1:09pm UTC
Hey ,
What are the differences between
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <cstring>
using namespace std;
inline int max(int a, int b)
{
return a>b ? a : b;
}
int main()
{
cout << max(10, 20);
return 0;
}
--------------------------------------------------------------------
and
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <cstring>
using namespace std;
int max(int a, int b)
{
return a>b ? a : b;
}
int main()
{
cout << max(10, 20);
return 0;
}
this code.Program output is same.
Last edited on Jul 31, 2013 at 1:10pm UTC
Jul 31, 2013 at 1:14pm UTC
There is no difference.
there would be a difference if another source file in your project defines the same function (the program wouldn't link without the keyword "inline")
Aug 1, 2013 at 1:06am UTC
There is. Its difference is the way the compiler handles. For regular function, a normal function call is generated and for inline functions, it writes a copy of the compiled function definition.