Description: D:\website\syllabus\study_matreials\c++\logo_pic\logo.jpg

Inline Functions



Note:  All the methods defined inside the class are by default  inline.

 

Inline methods are similar to #define macros but, unlike macros the inline functions are free from the side effects.

 

#include <iostream>

using namespace std;

#define Replace(x) x*x

inline int Test(int x)

{

    return x*x;

}

int main()

{

    int i=10;

    cout<<"Test(i++): "<<Test(i++)<<endl;

    i=10;

    cout<<"Test(++i): "<<Test(++i)<<endl;

    i=10;

    cout<<"Replace(i++): "<<Replace(i++)<<endl;

    i=10;

    cout<<"Replace(++i): "<<Replace(++i)<<endl;

}

 

Output:

Test(i++): 100

Test(++i): 121

Replace(i++): 100

Replace(++i): 144


Run in MyWhiteBoard


Copyright © Open Sky Technology