CSS Computer Science (Optional) — Paper-I, Section-A, Topic II subtopic. Complements the User-Defined Functions page.

What Are Standard Library Functions

Common Categories (C/C++ examples)

Standard Library vs User-Defined Functions

Standard Library Function User-Defined Function
Provided by the language/compiler Written by the programmer
Already tested and optimized Needs to be tested by the programmer
Accessed via header/import Declared and defined in the program

Worked Example

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

int main() {
    double result = sqrt(25.0);      // math.h -> 5.0
    char name[20] = "Ali";
    strcat(name, " Khan");             // string.h -> "Ali Khan"
    printf("%.1f %s", result, name);  // stdio.h
    return 0;
}

This single program pulls standard library functions from three different headers — sqrt() from <math.h>, strcat() from <string.h>, and printf() from <stdio.h> — without the programmer having to implement any of them.

💻 Code Examples: C & C++

The same task (compute a square root, build/modify a name) using C's traditional headers vs C++'s standard library equivalents:

C:

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

int main(void) {
    double result = sqrt(25.0);           // <math.h>
    char name[20] = "ali";
    strcat(name, " khan");                  // <string.h>
    name[0] = toupper(name[0]);             // <ctype.h>
    int *arr = malloc(3 * sizeof(int));     // <stdlib.h>
    printf("%.1f %s\n", result, name);
    free(arr);                               // <stdlib.h>
    return 0;
}