Function in c Porgramming

Function :

A function is a self contained program segment that carries out some specific, well defined task,
Every C program consists of one or more functions. Every C program must have main function.
Execution of program will always begin by carrying out the instructions in main.
Generally, a function will process information that is passed to it from the calling portion of the function and return a single value. Information is passed to the function via special identifiers called arguments.

Function Call:
A function can be called by specifying its name, a list of arguments, in contrast to the formal arguments that appear in the first line of the function definition.
Example:
....................................
//program to find out the sum of two number using function:

#include<stdio.h>
#include<conio.h>
int sum(int,int);
int main()
{
int a,b,c;
printf("enter two number:");
scanf("%d%d",&a,&b);
c=sum(a,b);
printf("sum is=%d",c);
getch();

}
int sum( int X,int Y)
{
int s;
s= X+Y;
return(s);
}
....................................



Advantages of using Function :
1.Writing function avoids rewriting the same code over and over. We can call the same function many times.
2.Using function, it becomes easier to write program and keep track of what they are doing.
3.Function helps to divide a large program into number of parts, Which makes it easier to understand, modify and debug

5 comments:

  1. How to find out the multiply of two number using function:

    ReplyDelete
    Replies
    1. in function block , change s= X*Y; others codes are same :)

      Delete
  2. Thank you for Providing the notes :)

    ReplyDelete
  3. What are the types of function ? and how to call function from one block to another block

    ReplyDelete

Powered by Blogger.