Function is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code.
functions in c and c++ has three things to be considered before using it in a program
- prototype - tells you what type of function that you are going to use in your program
- definition- defines the function
- call- calls the function
It is to be noted that where these three things comes in our program.
Function prototype comes before starting of the main function after the main function.
Function definition comes after the main function ends and
Function call comes inside the main function.
The general format of a function is |
<Return type> <Function name> <Parameter list>
{
local definitions;
statements;
Return value;
}
|
|
#include <stdio.h>
int f1(int,int); //prototype
void main(){
int i=3;
int j = 6;
int k = f1(i,j); //call
printf("%d",k);
}
int f1 (int j, int f) //definition
{
int k;
k = j + f;
return k;
}
|
|
No comments:
Post a Comment