Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating and using header files in C
#1
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;
}
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Text and binary files in C Qomplainerz 0 250 07-25-2023, 01:24 PM
Last Post: Qomplainerz
  Reading and writing files in C Qomplainerz 0 240 07-25-2023, 01:23 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 7 Guest(s)