Function in C

A function is nothing but a group of statement that works together to perform a task.

Types of function

  • User-defined function
  • Pre-defined function

User-Defined Function

A function that is defined by the user know as the user-defined function.

Below code shows the example of user-defined function

#include<stdio.h>
void main() {
 int a=3, b=3;
 // here void sum is user-defined function
 void sum(int a, int b) {
    printf("sum of no is :%d",(a+b));
  }
  sum (a,b); //function call
}
// output
// sum of no is :6

Pre-Defined Function

A function which is defined our header file of the code or we can say that function which is already known there work, for example, printf() and scanf() is defined in <stdio.h>

Below is the example of Pre-Defined of function

#include<stdio.h>
// main is the pre-defined function
void main() {
 int a=3, b=3;
 // here void sum is user-defined function
 void sum(int a, int b) {
    // printf is the pre-defined function
    printf("sum of no is :%d",(a+b));
  }
  sum (a,b); //function call
}
// output
// sum of no is :6

I hope you understand the basic concept of function, Still confused and having question in the mind.Feel free to ask.

0 0 vote
Article Rating

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x