> Online tutorial

arguments with no return type

Function with argument and no return type:

#include

#include

void print();

void line(int x,int y);

void main()

{

int a,b;

clrscr();

print();

printf("Enter thevalues");

scanf("%d%d",&a,&b);

line(a,b);

print();

getch();

}

void print()

{

int a;

for(a=0;a<=10;a++)

printf("-");

}

void line(int a,int b)

{

int c;

c=a+b;

printf("%d",c);

}

function types in c

No argument and no return type:

#include

#include

void printline();

void main()

{

int a;

clrscr();

printline();

printf("\nthis is world\n");

printline();

getch();

}

void printline()

{

int i;

for(i=1;i<=40;i++)

printf("-");

}

getch();

Declaration of function in c

Declaration of function:

1.function name

2.function type

3.list of parameter

syntax
Function type function_type(parameter list)

Example


int
mul(int m,int n);

function definition in c

Element of user defined function:

1.function definition

2.function call

3.function declaration


Defintion of function

A function definition ,also known as function implememtation shall include the following elements

1.function name

2.function type


3.list of parameter

4.local variable declaration

5.function statement

6.a return type

Syntax

Function type function_type(parameter list)

{

Local variable declaration;

Executable statement1;

Executable statement2;

Return statement;

}

Example:

void add(int a,int b)
{
int c;
return 0;
}


for above the statement

void          - return type
add          -function name
int a,int b  -parameter

recursive function in c

A multi fuction program
A function is a self contained block of code that perform a particular task.once a function has been designed

and packed .it can treated as a black box that takes some data from main program and return the values

Program:b

#include

Void printline();

Main()

{

printline();

printf(“this world”);

printline();

{

Void printline()

{

int i;

For(i=0;i<40;i++) Printf(“-“); } Getch(); } Output:

---------------------------------------------------------------------

This world

---------------------------------------------------------------------

Explanation:

The above pgm contains two user defined function

Main()function

Printline()function

As we know that the pgm execution can start with the main()during execution of main,the first statement can be encountered as
Printline()
Which indicates that it will be executed first and the main()returen function and again printline()

Can be executed .When this pgm main() can be call the user defined function prinline()

function two times and library function once