2. FUNCTIONS
• Function is the building block of C++.
• Used to reduce the size of the program by
calling and using them in different places in
the program.
• main()Function returns an integer value.
int main();
int main(int arg);
Function return a value using return statement.
3. FUNCTION PROTOTYPE
• The function interface to the compiler by
giving the details like number, data type,
arguments – function prototype.
• It is a declaration statement in calling program
type function name (argument list);
Eg:
float volume (int x, float y, z);
float volume (int, float, float);
4. CALL BY REFERENCE
• C++ permits to pass the parameters to the
functions by reference variable.
• When it is passed the formal argument act as
the actual argument in the calling function
void swap(int a, int b)
{
int t = a;
a = b;
b = t;
}
5. INLINE & RECURSION FUNCTION
• An inline function is a function that is expanded in
line when it is invoked.
• The compiler replaces the function call with the
corresponding function code.
inline function header
{
function body
}
• It send a request not a command
• Recursion means function call by itself ie one of the
statement in the function definition makes a call to
the same in which it is present.
6. CLASS
• Collection of objects – CLASS
• The entire set of data and code of an object can
be made a user defined data type by using
class.
• 2 Parts:
– Class Declaration – describe the type & scope of
its members
– Class function definitions – how the class
function are implemented.
7. • General format:
class class-name
{
private:
variable declaration;
function declaration;
public:
variable declaration;
function declaration;
};
Class item
{
int number;
float cost;
public:
void getdata(int a, float b);
void putdata(void);
};
8. • Class member – the class body contains the
declaration of variables and functions.
• Data member – variables declared inside the
class.
• Member function – the function declared
inside the class.
10. Outside the class definition
• Member function declared inside the class has to be
defined separately outside the class.
return-type class-name :: function-name
(argument declaration)
{
function body;
}
12. Inside the class definition
• It is to replace the function declaration by the actual
function definition inside the class.
class item
{
int number;
float cost;
public:
void getdata(int a, float b);
void putdata(void)
{
cout << number;
cout << cost;
}
};