C Programming language

Function in C: Introduction
Previous Home Next

What is function?

A fuction is a self contained block of statement that perform a coherent taskof some kind.

main()
{
message();
printf(“hi”)
}
message()
{
printf(“smile ”)
}

Write Any C program using at least one function.

If a program contain only one function , it must be main().
If a program contain more than one function then these can be contain in main().
There is no limit on number that might be present in a C program.
Each function in a program is called sequence specified by the function calls in main().
A function can be called from other function but can not be defined in the other function.

There are two types of function :

  1. library function(printf() ,scanf()).
  2. User defined (my()).

Passing the values between the function

main()
{
int a ,b,c,sum;
printf(“enter the values ”);
scanlf(“%d%d%d”,%a,%b,%c);
sum=calsum(a,b,c);        // actual argu./calling function
printf(“\nsum=%d”,sum);
}
Callsum(x,y,z)             // called function
int x,y,z;
{
Int d;
D=x+y+z;
return(d);
}                          
// a function can be return only one value at a time
Previous Home Next