What isFunctions? Explain Features of Functions,Types of Functions and Calling aFunction
·
is
a series of statements, enclosed by the Function and End Function statements
·
can
perform operations and can return a value
·
can
take arguments that are passed to it by a calling procedure
·
without
arguments, must include an empty set of parentheses ()
·
returns
a value by assigning a value to function name itself
Function
myfunction1()
Print "my fuction1"
End
Function
or
Function
myfunction2(a,b)
myfunction2=a+b 'assign value to function name
End
Function
How to
call Function Procedures:
Call
myfunction1() 'calling 1st function, without any return value
x=myfunction2(argument1,argument2) 'calling 2nd function, with a return value
Here you
call a Function called "myfunction2", the Function returns a value
that will be stored in the variable "x"
Functions
are used for Placing or Storing the Code which is to be Repeated Several Times.
For Example, if we need Same Code, then we must have to Write that Code Again
and Again So that for Removing this Task, we uses functions.
The
Functions are Some Storage Area which Contains set of Statements and the
Function Executes all the Contained Statements when a Special Call is made to
them. Once a Code is stored in the Function, then we can Store that Function
any time and Any Time we can call that Functions.
Functions are used for performing the
repetitive task or we can say the functions are those which provides us the
better efficiency of a program it provides us the facility to make a functions
which contains a set of instructions of the repetitive types or we need them in
a program at various places Thus a functions provides us the ability to make a
function which contains a code and then use them when a functions can call then
it executes the statements those are contained in it.
Functions
Provides us Following Features
1) Reusability of Code : Means Once a Code
has Developed then we can use that Code any Time.
2) Remove Redundancy: Means a user doesn’t
need to Write Code Again and Again.
3) Decrease Complexity: Means a Large
program will be Stored in the Two or More Functions. So that this will makes
easy for a user to understand that Code.
There are Two Types of Function
1) Built in Functions
2) User Defined functions
The
Functions those are developed by the user for their Programs are known as User
Defined Programs. When a user wants to make his Own Function, then he must have
to follow the Following Operations.
1) Function Declaration or
Prototyping
2) Function Defining
3) Calling a Function
1)
Function Declaration or Prototyping:For using a Function a user must have to
declare a Function. The Function declaration contains the Name of Function,
Return type of the Function and also the Number of Arguments that a User will
takes for performing the Operation.
The Function
Prototyping Contains
1) Return Type of a function: The Return
Function determines whether a Function will return any value to the Function.
If a Function is declared with the void Keyword or if a Function Contains a
void then that’s means a Function Never Returns a value. Means a Function will
Executes his statements one by one. And if a Function Contain any other data
type means if a Function Contains int or Float then the Function must return a
value to the user.
2) Name of Function : The Name of
Function must be valid and the name of function must be Start from any Alphabet
and the Name of Function doesn’t Contains any Spaces and the Doesn’t Contains
any Special Character For Example Space , * sign etc.
3) Argument List: A Function may have zero
or More Arguments. So that if we want to call a Function. Then we must have to
Supply Some Arguments or we must have to pass some values those are also called
as the Argument List. So that The Argument List is the total Number of
Arguments or the Parameters those a Function Will takes. So that We must have
Supply Some Arguments to the Functions,. The Arguments those are used by the
Function Calling are known as the Actual Arguments and the Arguments those are
used in the Function declaration are Known as the Formal Arguments, When we
call any Function then the Actual Arguments will Match the Formal Arguments and
if a proper Match is Found, then this will Executes the Statements of the
Function otherwise this will gives you an error Message.
There
are Two Ways for Calling a Function
1) Call by Value:-when we call a Function
and if a function can accept the Arguments from the Called Function, Then we
must have to Supply some Arguments to the Function. So that the Arguments those
are passed to that function just contains the values from the variables but not
an Actual Address of the variable.
So that
generally when we call a Function then we will just pass the variables or the
Arguments and we doesn’t Pass the Address of Variables , So that the function
will never effects on the Values or on the variables. So Call by value is just
the Concept in which you must have to Remember that the values those are Passed
to the Functions will never effect the Actual Values those are Stored into the
variables.
2) Call By Reference :-When a function is
called by the reference then the values those are passed in the calling
functions are affected when they are passed by Reference Means they change
their value when they passed by the References. In the Call by Reference we
pass the Address of the variables whose Arguments are also Send. So that when
we use the Reference then, we pass the Address the Variables.
When we
pass the Address of variables to the Arguments then a Function may effect on
the Variables. Means When a Function will Change the Values then the values of
Variables gets Automatically Changed. And When a Function performs Some
Operation on the Passed values, then this will also effect on the Actual
Values.