What are the predefined functions in C language?

In C programming, functions are classified into two main types −

  • Predefined functions (Library functions)
  • User-defined functions

Predefined functions are pre-written functions available in C standard libraries. They provide ready-to-use functionality for common programming tasks, helping developers write efficient and error-free code.

Syntax

#include <library_name.h>
return_type function_name(parameters);

Key Features of Predefined Functions

  • Already defined in system libraries
  • Tested and optimized for performance
  • Reduce development time and effort
  • Require appropriate header file inclusion
  • Follow standard syntax and conventions

Common Mathematical Functions

The math.h library provides various mathematical functions −

Function Purpose Example
sqrt(x) Square root of x sqrt(25) = 5.0
pow(x,y) x raised to power y pow(2,3) = 8.0
ceil(x) Round up to nearest integer ceil(4.2) = 5.0
floor(x) Round down to nearest integer floor(4.8) = 4.0

Example: Basic Mathematical Functions

Here's a program demonstrating common predefined functions −

#include <stdio.h>
#include <math.h>

int main() {
    double x = 25.0, y = 3.0;
    
    printf("Original number: %.1f
", x); printf("Square root: %.2f
", sqrt(x)); printf("Power (%.1f^%.1f): %.2f
", x, y, pow(x, y)); printf("Ceiling of 4.3: %.1f
", ceil(4.3)); printf("Floor of 4.8: %.1f
", floor(4.8)); return 0; }
Original number: 25.0
Square root: 5.00
Power (25.0^3.0): 15625.00
Ceiling of 4.3: 5.0
Floor of 4.8: 4.0

Example: String Functions

The string.h library provides string manipulation functions −

#include <stdio.h>
#include <string.h>

int main() {
    char str1[50] = "Hello";
    char str2[50] = "World";
    char str3[100];
    
    printf("String 1: %s
", str1); printf("String 2: %s
", str2); printf("Length of str1: %lu
", strlen(str1)); strcpy(str3, str1); strcat(str3, " "); strcat(str3, str2); printf("Concatenated: %s
", str3); return 0; }
String 1: Hello
String 2: World
Length of str1: 5
Concatenated: Hello World

Common Library Functions by Category

Library Functions Purpose
stdio.h printf(), scanf(), fopen() Input/Output operations
math.h sqrt(), pow(), sin(), cos() Mathematical calculations
string.h strlen(), strcpy(), strcmp() String manipulation
stdlib.h malloc(), free(), rand() Memory management, utilities

Conclusion

Predefined functions in C provide essential functionality through standard libraries, making programming more efficient and reliable. They eliminate the need to write common operations from scratch and ensure consistent, optimized performance across different platforms.

Updated on: 2026-03-15T13:34:18+05:30

11K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements