Last active
October 18, 2015 14:21
-
-
Save checkaayush/428ddd735c4fa90db43a to your computer and use it in GitHub Desktop.
Creating and using your own header file in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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