QP School
Creating and using header files in C - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: C 18 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=32)
+--- Thread: Creating and using header files in C (/showthread.php?tid=5108)



Creating and using header files in C - Qomplainerz - 07-25-2023

Header files contain function prototypes and other declarations.

// math_operations.h
#ifndef MATH_OPERATIONS_H
#define MATH_OPERATIONS_H

int add(int a, int b);
int subtract(int a, int b);

#endif

// math_operations.c
#include "math_operations.h"

int add(int a, int b) {
    return a + b;
}

int subtract(int a, int b) {
    return a - b;
}

// main.c
#include <stdio.h>
#include "math_operations.h"

int main() {
    int result = add(10, 5);
    printf("Addition: %d\n", result); // Output: 15

    result = subtract(10, 5);
    printf("Subtraction: %d\n", result); // Output: 5
    return 0;
}