25 Nested classes and inline functions in C++ zoom | C++ Programming Tutorial for beginners | cpp

152 Просмотры
Издатель
#Inline functions in C++ :
in c++ if programer made any function as inline funtion, then the compiler places/keeps a copy of the code of that function at each point/time whereever the function is called at compile time.

- Any changes to an inline function, it could require all the callee program/clients of the function to be recompiled because compiler would need to replace all the code once again otherwise existing/old code functionality will be executed.

- to make any function as inline we need use inline keyword precede/before by function name and define the function before any calls are made to that function. The compiler can ignore the inline qulifier in case defined inline function is more than one line of code/statements.

inline returntype funcName(){
//single line of code
}


Example Program:
#include iostream
using namespace std;
inline int findMax(int a,int b){
return a b?a:b; //ternary operator
}
int main(){
int p,q;
cout "\nEnter first number ";
cin p;
cout "\nEnter Second number ";
cin q;
cout "\n";
cout "\n maximum of " p " and " q " is : " findMax(p,q);
cout "\n maximum 20,10 is : " findMax(20,10);
cout "\n maximum 234,9876 is : " findMax(234,9876);
getchar();
getchar();
return 0;
}
Категория
Язык программирования C++
Комментариев нет.