C - FUNCTIONS

 FUNCTIONS

C allows programmers to define their own functions for carrying out versions individual tracks. C function can be classified into two categories namely library function and user defined function. printf, scanf, sqrt etc are the example of library function. The main distinction between these two categories is that library functions are not required to be written by us whereas a userdefined has to be developed by the user at the time of writing a program. If a program is divided into functional part, then each part may be independently coded and later combined into a single unit. These subprograms called “Functions” as much easier to understand debug and test.

Function definition:

This is used to define the body of the function.

data-type function-name(type1 a1, type2 a2... typen an)

{

..........

(body of the function)

..........

}

 

Function call :

A function call is an expression of the form:

function-name (argument-list);

where,

Function-name : Name of the function called

Argument-list : A comma separated list of expressions that constitute the arguments to the function.

Example –

main()

{

printf(“Hello”);

fun();

printf(“Students”);

}

fun()

{

printf(“BCA”);

}

 

Output-

Hello

BCA

Students

 

TYPES OF FUNCTION

Library function / Predefined function –

The programmer does no need to write these functions since they are predefined and all is needed do is to call the function and pass argument if necessary.

Some Library functions are :-

(a) math.h - >

ciel() , floor() , log() , sqrt() , pow() etc.

(b) stdio.h - >

getchar() , putchar() , getche() , gets() , puts() , fflush() etc.

(c) string.h - >

strlen() , strcpy() , strcat() , strcmp() , strrev() etc.

(d) ctype.h - >

toupper() , tolower() , isupper() , islower() , isdigit() etc.

(e) conio.h - >

window() , puttext() , clrscr() , gotoxy() , delay() etc.

 

User Defined Function –

In ‘C’ user can also create functions for doing any specific task of the program such functions are called user defined functions.

In ‘C’ we may define a function by using any of the following ways-

(a) Function with no argument and no return value.

(b) Function with argument and no with no return value.

(c) Function with argument and with return value.

Prototype of function –

When a function returns a non-integer value then this function must be declare before defining it. This declaration is known as function prototyping.

SYNTAX

return type function name( data type arg1);

 

Comments

Popular posts from this blog

Courses After 12th Science

MS Office Versions List

Computer - Network Topologies