Chapter 1: Introduction to Object Oriented Paradigm Software Crisis



Yüklə 379,92 Kb.
Pdf görüntüsü
səhifə7/10
tarix26.06.2023
ölçüsü379,92 Kb.
#135215
1   2   3   4   5   6   7   8   9   10
C Chapter1

Chapter 2 
Inline Function
• To eliminate the cost of call of small function, C++ proposes a new feature called inline function 
• An inline function is expanded in a line when the function is called or invoked. i.e. the compiler 
replaces the function call with the corresponding function code.
• All inline function must be defined before they are called. 
Syntax:
inline return_type function function_name (argument_list) 

Function body 

• Some of the situation where inlined expression may not work are; 
For function returning value, if a loop ‘switch’ or ‘goto’ statement. 
➢ For the function not returning the value if a return statement exist 
➢ If the function consists static variable 
➢ If the inline functions are recursive 
Example program of inline function: 
Default Argument 
• Argument is the data passed in the function. Default argument is useful in situation where some 
argument have same value. For e.g. the bank interest for all customers is same. 
Unlike C, C++ allows us to call a function without specifying all its arguments. IN such cases, the 
function assigns a default value to the parameter which doesn’t has the matching argument in 
the function call. 
• Default values are specified when the function is declared. 
Example: 
float amount(float principal, int period, float r=0.15) 
float value = amount(5000,7); //one argument missing. Explicit value of r =0.15 


10 
Example Program of default argument 
#include 
using namespace std; 
class weight 

float w; 
public: 
void process(float m, float g=9.8) 
//here g = 9.8 is used as default argument 

w= m*g; 
cout<<"weight="<
}; 
int main() 

weight ob; 
ob.process(10,1.6); 
return 0; 


Yüklə 379,92 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   10




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin