Skip to content

Instantly share code, notes, and snippets.

@checkaayush
Last active October 18, 2015 14:21
Show Gist options
  • Save checkaayush/428ddd735c4fa90db43a to your computer and use it in GitHub Desktop.
Save checkaayush/428ddd735c4fa90db43a to your computer and use it in GitHub Desktop.
Creating and using your own header file in C
// Instructions:
// Compilation Command: gcc mainProgram.c myLibrary.c
// Creates required object files.
// Execution Command: ./a.out
#include <stdio.h>
// Including my library
#include "myLibrary.h"
int main()
{
int a = 4, b = 5;
int product = multiply(a, b);
printf("Product: %d x %d = %d\n", a, b, product);
return 0;
}
// This file contains definitions of functions
// declared in included header files.
// In this case, for "myLibrary.h".
#include "myLibrary.h"
// Takes 2 integers as arguments and returns their product.
int multiply(int a, int b) {
return a*b;
}
// Declaration of my function: multiply
int multiply(int, int);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment