Functions are very useful in c++ because it is used for re-usability of code this means we write a statement at once then we call that statement number of times and from this way we never write whole code again and again. function are work with three statements.
syntax of function declaration:
datatype function(parameters);
consider example for function declaration.
void sum(int a,int b);
syntax of function calling:
function(parameters without datatype);
example:
sum(a,b);
syntax function definition:
datatype function(parameters)
{
statement;
}
example:
void sum(int a,int b)
{
int c;
c=a+b;
cout<<c;
}
- function declaration
- function calling
- fuction definition
syntax of function declaration:
datatype function(parameters);
consider example for function declaration.
void sum(int a,int b);
syntax of function calling:
function(parameters without datatype);
example:
sum(a,b);
syntax function definition:
datatype function(parameters)
{
statement;
}
example:
void sum(int a,int b)
{
int c;
c=a+b;
cout<<c;
}
