inline functions

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
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")
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.
Topic archived. No new replies allowed.