functuion in c language
Functions :
- Functions are used to divide a large C program into smaller pieces.
- Function can be called multiple or several times to provide reusability and modularity to the C program.
- Functions are also called as procedure or subroutines.
- It is a piece of code to accomplish certain operation
Advantages of Functions :
- We can avoid rewriting same logic or code through functions.
- We can divide the work among programmers using functions.
- We can easily debug or can find bugs in any program using functions.
Function Aspects :
There are 3 aspects of function :-
- Declaration
- Definition
- Call
there two type of function
1. library function
2. user define function
in this all doubt is clear
#include<stdio.h>
int sum ( int a , int b)
{
return a+b;
}
int printstar( int n )
{
char i;
for (int i = 0; i < 7; i++)
{
printf("%c\n",'*');
}
}
int takenumber()
{
int i;
printf(" enter any num\n");
scanf("%d",&i);
return i;
}
int main(int argc, char const *argv[])
{
int a, b, c ,d;
a = 4;
b = 5;
c = sum (a , b);
printstar(7);
d = takenumber();
printf("the sum is %d\n", c);
printf(" the entered num is %d", d);
return 0;
}
Comments
Post a Comment