Functions

 What is Function ?

   In a Program to perform articular task number of times which is having more number of statements, instead of writing those statements number of time we can define a sub routine called Function.

The purpose of function is reusability.

Function has three parts

1. Function declaration - before the main()

2. Function Calling - within the main()

3. Function Definition - after the main()


Functions are following categories

1. Functions with no arguments, no return value

2, Functions with arguments, no return value

3. Function with arguments and return value


while giving the function definition we can use as follows


   type specifier function_name(arg1,arg2,...)

   {

      statements;

   }

In the above type specifier represent what type of value the function is going to return. If the function can't return any value we can represent with void otherwise we can use any related data type.


to return the value we can use any one of the following 

formats of return statement

   1. return variable

   2. return 1

   3. return 0

   4. return expression

   5. return conditional expression


while working with functions we can pass some arguments called parameters. parameter passing mechanisms are two types

1. call by value

2. call by reference

the difference between call by and call by reference is -

In case of call by value we can pass actual values of the variables as an arguments, in case of call by reference we can pass address of the variables as an arguments.

In case of call by value actual values are not effected, in case call by reference it can





Comments

Popular posts from this blog

Example Programs for Control Flow Statements

SQL Operators