diff --git a/clang.md b/clang.md index c3251e135774b1e937396baff0c6e630f381d9f9..dda931065463ef2ecc7497c298d02be261fc9c8a 100644 --- a/clang.md +++ b/clang.md @@ -197,4 +197,38 @@ int main() { This list goes on, you can find more information about undefined behaviours in this [thesis](https://solidsands.com/wp-content/uploads/Master_Thesis_Vasileios_GemistosFinal.pdf) and in the [C99 Standard](https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf) -## Memory Model in C +## True or False + +There is no explicit `Boolean` type in old-school C. Alternatively, you can use the boolean type in the header file `#include <stdbool.h>` introduced in `C99`. + +```c +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> + +int main(void) { + bool keep_going = true; // Could also be `bool keep_going = 1;` + while(keep_going) { + printf("This will run as long as keep_going is true.\n"); + keep_going = false; // Could also be `keep_going = 0;` + } + printf("Stopping!\n"); + return EXIT_SUCCESS; +} +``` + +### What evaluates to FALSE in C? + +- `0` (integer) +- `NULL` +- Basically anything where all the bits are 0 is false + +### What evaluates to TRUE in C? + +- Anything that isn't false is true + +## Pointers in C + +Pointers are probably the single largest source of bugs in C, so be careful when you use them. + +