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
#ifndef HEADER_FILE //include guards prevent multiple includsion | |
#define HEADER_FILE //if not yet defined, define it | |
//optional but recommended | |
int square (int input); | |
int cube(int input); | |
int power(int input, int exponent); | |
int recursivePower(int input, int exponent); | |
void changeVal(int *a); | |
int oldestValue( int *ages, int size); |
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
#include "5.2-libraries.h" | |
int square (int input) | |
{ | |
return input * input * input; | |
} | |
int cube(int input) | |
{ | |
return input * input * input; | |
} |
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
/* | |
gcc -c 5.2-libraries.c | |
cc -c 5.2-libraries-main.c | |
gcc 5.2-libraries.o 5.2-libraries-main.o | |
./a.out | |
You can also get a custom name like this: | |
gcc -o main 5.2-libraries.o 5.2-libraries-main.o | |
//research makefile to make life easier |
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
#include <stdio.h> | |
int square (int input) | |
{ | |
return input * input; | |
} | |
int cube(int input) | |
{ | |
return input * input * input; | |
} |
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
#include <stdio.h> | |
#include <string.h> | |
int main() | |
{ | |
//strings are just character arrays | |
//the string ends with \0 (null character) | |
//not always the last possible index in the string. | |
char name[20]; |
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
#include <stdio.h> | |
int main() | |
{ | |
//arrays are pretty simple. | |
//It's a collection of items all of same data type | |
int ages[] = {1, 3, 4, 54, 34, 2}; | |
int size = 6; |
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
//loops. 3 main kinds | |
#include <stdio.h> | |
int main() | |
{ | |
//Each loop has three pieces and it happens at distinct times | |
//initialization (once at beginning) | |
//comparison (before each iteration) | |
//update (at the end of each iteration) |
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
/* | |
Everything inside of if is ultimately evaluated to true or false | |
*/ | |
#include <stdio.h> | |
#include <stdbool.h> | |
int main() |
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
#include <stdio.h> | |
int main() | |
{ | |
/* | |
//reference - https://www.tutorialspoint.com/cprogramming/c_operators.htm | |
//so far we've worked with some basic operators | |
///////////// Plus and Minus ///////////// (unary) | |
+ |
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
#include <stdio.h> | |
#include <stdbool.h> | |
int main() | |
{ | |
int a = 10; //integer | |
double b = 10.0; //double | |
float c = 10.0; //float (similar to double but less precise) | |
char d = 'a'; //string | |
char e[] = "The easiest way to define a string"; |