From c7f6f04ac3e78ffd0a84359298e27445cd878742 Mon Sep 17 00:00:00 2001 From: Mactavish <maczhanchao@yahoo.com> Date: Sun, 23 Apr 2023 13:59:52 +0200 Subject: [PATCH] update --- clang.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/clang.md b/clang.md index c3251e1..dda9310 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. + + -- GitLab