
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What are the different types of functions in C Programming?
Functions are broadly classified into two types which are as follows −
- predefined functions
- user defined functions
Predefined (or) library functions
These functions are already defined in the system libraries.
Programmer can reuse the existing code in the system libraries which is helpful to write error free code.
User must be aware of syntax of the function.
For instance, sqrt() function is available in math.h library and its usage is y= sqrt (x), where x= number must be positive.
If x value is 25, i.e., y = sqrt (25) then ‘y’ = 5.
In the same way, printf() is available in stdio.h library and clrscr() is available in conio.h library.
Program
#include<stdio.h> #include<conio.h> #include<math.h> main (){ int x,y; clrscr (); printf (“enter a positive number”); scanf (“ %d”, &x) y = sqrt(x); printf(“squareroot = %d”, y); getch(); }
Output
Enter a positive number 25 Squareroot = 5
User defined functions
These functions must be defined by the programmer or user.
Programmer has to write the coding for such functions and test them properly before using them.
The syntax of the function is given by the user so there is no need to include any header files.
For example, main(), swap(), sum(), etc., are some of the user defined functions.
Example
#include<stdio.h> #include<conio.h> main (){ int sum (int, int); int a, b, c; printf (“enter 2 numbers”); scanf (“ %d %d”, &a ,&b) c = sum (a,b); printf(“sum = %d”, c); getch(); } int sum (int a, int b){ int c; c=a+b; return c; }
Output
Enter 2 numbers 10 20 Sum = 30
- Related Articles
- What are the different categories of functions in C Programming?
- Different Types of SQL Functions
- What are the scope rules to functions in C programming?
- What are different types of constants in C++?
- What are fundamental data types in C++ programming?
- What are the types of Finance Functions?
- What are the different data types of arrays in C#?
- What are the different types of pointers in C language?
- What are the different types of keywords in C language?
- What are different types of constants in C language?
- What are different types of data in C language?
- What are the different types of filters in C# ASP.NET WebAPI?
- What are the different types of psychotherapy?
- What are the different types of DBMS?
- What are the different types of ISDN?
