Functions, Function Declaration Assignment Help

Assignment Help: >> Introduction to C language >> Functions, Function Declaration

Introduction to Functions

 A function is a self-contained subprogram, which is meant to do some specific well defined task. A C program consists of one or more functions. If a program has only one function then it must be the main() function. If the program contains multiple functions, their definitions may appear in any order, though     they must be independent of one another. That is, one function definition cannot be embedded within another.

 Definition of Function 

A function definition has two principal components: the first line (including the argument declarations), and the body of the function. The first line of a function definition contains the type specification of the value returned by the function, followed by the function name, and (optionally) a set of argument, separated by commas and enclosed in parentheses. Each argument is preceded by its associated type declaration. An empty pair of parenthesis must follow the function name if the function definition does not include any arguments.

In general terms, the first line can be written as

data_type  function_name (type1 arg1, type2 arg2, ..............,typen argn)            

Where data_type represents the data type of the item that is returned by the function, function_name represents the function name, and type 1, type 2,......,type n represent the data types of the arguments arg1,arg2,..........,arg n. 

Function Declaration 

If a function returns a value of data type int then it is not necessary to declare the function, because by default it returns an int value. The compiler assumes that this function will return an int value. But if the function returns a value other than int, such as float, array, structure etc, then it is necessary to declare it before the function call.

Example:

main( )

{

                float circle( );        // Declaration of Function

                  ...............

  ................

}

circle( )                 // Definition of Function

{

                 ..................

                ..................

                ..................

}

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd