FUNCTION IN C++
FUNCTIONS IN C++
Need of Function
Function Block
Function Structure
datatype functionname(); //function declaration
datatype functionname() //function defination
{
.......... //function body
..........
}
1.Default Argument Function
In this function argument value is provided during declaration
Let's take example
CODE:
#include<iostream>
using namespace std;
inline int swap(int &a,int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int main()
{
cout << "Write a program that illustrates the use of default arguments.\n\n\n";
int x,y;
cout << "Enter the value of x:";
cin >> x;
cout << "Enter the value of y:";
cin >> y;
swap (x,y);
cout << "x=" << x << endl;
cout << "y=" << y << endl;
}
Need of Function
- To simplify a program
- Reduce the length of program
- Time of execution is reduce
- Less memory required
Function Block
- Function Declaration
- Function Definition
- Function Body
Function Structure
datatype functionname(); //function declaration
datatype functionname() //function defination
{
.......... //function body
..........
}
1.Default Argument Function
In this function argument value is provided during declaration
Let's take example
CODE:
#include<iostream>
using namespace std;
inline int swap(int &a,int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int main()
{
cout << "Write a program that illustrates the use of default arguments.\n\n\n";
int x,y;
cout << "Enter the value of x:";
cin >> x;
cout << "Enter the value of y:";
cin >> y;
swap (x,y);
cout << "x=" << x << endl;
cout << "y=" << y << endl;
}
OUTPUT:
0 Comments