diff options
| author | mo khan <mo.khan@gmail.com> | 2020-07-29 11:19:20 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-07-29 11:19:20 -0600 |
| commit | e10ec83982b47a5a706223a3ec80e609aba0a8ac (patch) | |
| tree | 61c2588beaa9f2d3bb0f8a7a825a73982c5dd869 | |
| parent | 976a848640034f19fc4203f02928c2be734aafb1 (diff) | |
Episode 4: Slides
| -rw-r--r-- | README.md | 46 | ||||
| -rw-r--r-- | main.c | 35 | ||||
| -rw-r--r-- | main.js | 7 |
3 files changed, 68 insertions, 20 deletions
@@ -17,14 +17,9 @@ We tell the computer what to do. Topics * variables - - - * statements/expressions * looping - - "mo" ------- @@ -146,3 +141,44 @@ OR | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 1 | + + +* functions: behaviour +* structs: data + + +code + data = programming + + +allocation a variable -> stack + + + +* pass by value + + x -> clone -> x1 + +(x1) + \x1\ + \x1\ + \x1\ + (x1 * 2) + - + +* pass by reference + + `*x` +(x) + \x\ + \x\ + \ \ + ( ) + - + +Workbench + +* text editor (vscode, emacs, vim, nano, textmate) +* compiler toolchain + * GNU: gcc + * LLVM: clang +* terminal: @@ -2,22 +2,27 @@ #include <string.h> #include <stdlib.h> +typedef struct { + int age; + int happiness; // 0 sad, 100 happy +} Person; + +void slide(Person *person) +{ + person->happiness += 10; +} + +// pass by value +// pass by reference int main(int argc, char *argv[]) { - // AND && - // OR || - // - int age = 30; + Person *mo = malloc(sizeof(Person)); + mo->age = 36; + mo->happiness = 70; - if (/* */) - { - printf("Fly to Hawaii\n"); - } - else - { - printf("Camp in the back yard\n"); - } -} + printf("Before: age(%d), happiness(%d)\n", mo->age, mo->happiness); + + slide(mo); -// 1. compile: c -> machine -// 2. run: machine -> os + printf("After: age(%d), happiness(%d)\n", mo->age, mo->happiness); +} @@ -0,0 +1,7 @@ +function main() { + let person = { age: 30 }; + + function slide(person) { + person.age = 100; + } +} |
