07-25-2023, 01:29 PM
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;
}
// 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
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos