Last active
October 14, 2015 23:45
-
-
Save jadudm/5b22e19c6a182ae70e33 to your computer and use it in GitHub Desktop.
Some starter code for an exam question.
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 <stdlib.h> | |
#include <stdbool.h> | |
/* Constants */ | |
#define NUMBER_OF_TESTS 4 | |
#define A 0 | |
#define B 1 | |
void And (bool a, bool b, bool *out) { | |
if (a && b) { | |
*out = true; | |
} else { | |
*out = false; | |
} | |
} | |
void Xor (bool a, bool b, bool *out) { | |
} | |
void HalfAdder (bool a, bool b, bool* sum, bool* carry) { | |
} | |
int main () { | |
bool a, b; | |
bool *r1, *r2; | |
bool tests[4][2] = {{false, false}, | |
{false, true}, | |
{true, false}, | |
{true, true} | |
}; | |
int ndx; | |
/* Allocate space for pointers */ | |
r1 = (bool *)malloc(sizeof(bool)); | |
r2 = (bool *)malloc(sizeof(bool)); | |
/* Test And */ | |
for (ndx = 0; ndx < NUMBER_OF_TESTS ; ndx++) { | |
And (tests[ndx][A], tests[ndx][B], r1); | |
printf("And: %i %i -> %i\n", | |
tests[ndx][A], | |
tests[ndx][B], | |
*r1 | |
); | |
} | |
/* Print a pretty separator */ | |
printf("-=-=-=-=-=-=-=-=-=-=-=--=-=\n"); | |
/* Test Xor */ | |
for (ndx = 0; ndx < NUMBER_OF_TESTS ; ndx++) { | |
} | |
/* Print a pretty separator */ | |
printf("-=-=-=-=-=-=-=-=-=-=-=--=-=\n"); | |
/* Test HalfAdder */ | |
for (ndx = 0; ndx < NUMBER_OF_TESTS ; ndx++) { | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment