FUNCTIONS IN C
What is Functions:-
* Functions are used to divide a large c programm into smaller piece.
* Functions can be called multiples times to provide reusabilility and modularity to the c programm.
* Also called procedure or subroutine.
ADVANTAGES OF C FUNCTION:-
* We can rewriting same logic through functions.
* We can divide work among programmer using function.
* We can easily debug a program using function.
DECLARATION,DIFNATION AND CALL:-
* A Function is declared to tell a compiler about its existance.
* A Function is defined to get some task done.
* A Function is called in order to be use.
TYPES OF FUNCTION:-
* Library functions-Functions include in c header files.
* User defined functions-Functions created by C programmer to reduce complexity of a program.
FUNCTIONS CODE EXAMPLES:-
* Without arguments and without return value.
* Without arguments and with return value.
* With arguments and without return value.
* With arguments and with return value.
With arguments and without return value.
#include <stdio.h>
int sum(int a, int b);
void printstar(int n)
{
for (int i = 0; i < n; i++)
{
printf("%c",'*');
}
}
int main(){
int a,b,c;
a=9;
b=12;
c=sum(a,b);
printstar(18);
return 0;
}
int sum(int a, int b)
{
return 0;
}
With arguments and with return value.
#include <stdio.h>
int sum(int a,int b);
int main(){
int a, b, c;
a = 9;
b = 12;
c = sum(a,b);
printf("The sum is %d\n",c);
return 0;
}
int sum(int a, int b)
{
return a+b;
}