There are two types of Function available in C-programming language:
![]() |
Types of function in c |
1.Pre-Defined Functions.
2.User-Defined Functions.
Above are the two well-known types of functions available in c-programming. Now we'll see them one-by-one in details.
Pre-Defined Functions:
Functions which are already defined in c-library are called pre-defined functions in c-programming language. We don't need to declare them in our program because they are already defined in c-library and we can call them anytime in our program, but to use them in our program we need to include header files in which those functions are declared. for example : we need to include 'stdio.h' to use printf() and scanf() functions.
Example:
Program for Pre-Defined Functions:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the value of a :");
scanf("%d",&a);
printf("Enter the value of b :");
scanf("%d",&b);
c = a + b;
printf("The sum of %d and %d is %d",a,b,c);
return 0;
}
here scanf() and printf() are two pre-defined functions in c-programming language.
User-Defined Functions:
Functions which are declared within a program or Functions which are declared by users to perform some actions whenever it is called are user-defined functions in c-programming language. It can be declared above or below the main function. and can be called anytime in a c-program.
How to declare a function?
How to call a function?
Program for User-Defined Functions:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter the value of a :");
scanf("%d",&a);
printf("Enter the value of a :");
scanf("%d",&b);
c = add(a,b);
printf("The sum of %d and %d is %d",a,b,c);
return 0;
}
int add(int x, int y)
{
return x+y;
}
here scanf() and printf() are two pre-defined functions and add() is user-defined functions in c-programming language.
0 Comments
Post a Comment