Function – Declaration Arguments Return Types
Function is a set of statements and operations which performs a specific task.Every code has atleast one function (main function) and more can be created for simplifying and reducing the same code over and over again.
Example for a code in c++
using namespace std;
int myFunction(int x, int y) //declaration of the function and the arguments .
return z; //returns the integer value z
void main() //declaration of main function with no arguments
myFunction(a,b); //calling the function to add the numbers
When creating a new function we need to tell the computer the name, the arguments(if any) and the type of the function which is called as the declaration of that function.
int add(int a,int b)
Note 1- Good declarations are always in camelCase as they are more readable, example – declaring a functioname name as myfunctionname is bad coding standard and myFunction name is good.
The values given/passed to the function that it may use in it’s operation are known as it’s arguments. A function may or may not have any values in it.
int add(int a,int b) // here a,b are the arguments and int tells us they are integer
A function may value after it runs completely, the type of value it returns is called the return type, it can be int (integer), float (decimal),char (alphabet of symbols), void (nothing is returned )… etc .
int add() //returns integer value
float divide()//returns decimal value
void print()//no value is returned