You are on page 1of 2

Functions What is Functions?

Explain Features of Functions,Types of Functions and Calling a Function


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 rite that Code !gain and !gain So that for Removing this Tas", we uses functions. The Functions are Some Storage !rea which Contains set of Statements and the Function Executes all the Contained Statements when a Special Call is made to them. #nce a Code is stored in the Function, then we can Store that Function an$ time and !n$ Time we can call that Functions. Functions are used for performing the repetitive tas" or we can sa$ the functions are those which provides us the better efficienc$ of a program it provides us the facilit$ to ma"e a functions which contains a set of instructions of the repetitive t$pes or we need them in a program at various places Thus a functions provides us the abilit$ to ma"e 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 %& Reusabilit$ of Code ' (eans #nce a Code has )eveloped then we can use that Code an$ Time. *& Remove Redundanc$' (eans a user doesn+t need to rite Code !gain and !gain.

,& )ecrease Complexit$' (eans a -arge program will be Stored in the Two or (ore Functions. So that this will ma"es eas$ for a user to understand that Code. There are Two T$pes of Functions %& .uilt in Functions *& /ser )efined functions

The Functions those are provided b$ C -anguage are refers to the Built in Functions For example. cin and cout, getch , Clrscr are the Examples of .uilt in Functions. So that all the functions those are provided b$ the C00 -anguage are Pre defined and Stored in the Form of header Files so that a user doesn+t need to 1now how this Function has developed and a user 2ust use that Function. .ut in the other hand the Functions those are developed by the user for their Programs are "nown as User Defined Programs. hen a user wants to ma"e his #wn Function, then he must have to follow the Following #peration %& Function )eclaration or Protot$ping *& Function )efining ,& Calling a Function %& Function )eclaration or Protot$ping'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 /ser will ta"es for performing the #peration.

The Function Prototyping Contains %& Return T$pe of a function' The Return Function determines whether a Function will return an$ value to the Function. 3f a Function is declared with the void 1e$word or if a Function Contains a void then that+s means a Function Never Returns a value. (eans a Function will Executes his statements one b$ one. !nd if a Function Contain an$ other data t$pe means if a Function Contains int or Float then the Function must return a value to the user. *& 4ame of Function ' The 4ame of Function must be valid and the name of function must be Start from an$ !lphabet and the 4ame of Function doesn+t Contains an$ Spaces and the )oesn+t Contains an$ Special Character For Example Space , 5 sign etc. ,& !rgument -ist' ! Function ma$ have 6ero or (ore !rguments. So that if we want to call a Function. Then we must have to Suppl$ Some !rguments or we must have to pass some values those are also called as the !rgument -ist. So that The !rgument -ist is the total 4umber of !rguments or the Parameters those a Function ill ta"es. So that e must have Suppl$ Some !rguments to the Functions,. The !rguments those are used b$ the Function Calling are "nown as the !ctual !rguments and the !rguments those are used in the Function declaration are 1nown as the Formal !rguments, hen we call an$ Function then the !ctual !rguments will (atch the Formal !rguments and if a proper (atch is Found, then this will Executes the Statements of the Function otherwise this will gives $ou an error (essage. There are T o !ays for Calling a Function %& Call by "alue'7when we call a Function and if a function can accept the !rguments from the Called Function, Then we must have to Suppl$ some !rguments to the Function. So that the !rguments those are passed to that function 2ust contains the values from the variables but not an !ctual !ddress of the variable. So that generall$ when we call a Function then we will 2ust pass the variables or the !rguments and we doesn+t Pass the !ddress of 8ariables , So that the function will never effects on the 8alues or on the variables. So Call b$ value is 2ust the Concept in which $ou must have to Remember that the values those are Passed to the Functions will never effect the !ctual 8alues those are Stored into the variables. *& Call By Reference '7 hen a function is called b$ the reference then the values those are passed in the calling functions are affected when the$ are passed b$ Reference (eans the$ change their value when the$ passed b$ the References. 3n the Call b$ Reference we pass the !ddress of the variables whose !rguments are also Send. So that when we use the Reference then, we pass the !ddress the 8ariables. hen we pass the !ddress of variables to the !rguments then a Function ma$ effect on the 8ariables. (eans hen a Function will Change the 8alues then the values of 8ariables gets !utomaticall$ Changed. !nd hen a Function performs Some #peration on the Passed values, then this will also effect on the !ctual 8alues.

You might also like