summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-07-29 11:19:20 -0600
committermo khan <mo.khan@gmail.com>2020-07-29 11:19:20 -0600
commite10ec83982b47a5a706223a3ec80e609aba0a8ac (patch)
tree61c2588beaa9f2d3bb0f8a7a825a73982c5dd869
parent976a848640034f19fc4203f02928c2be734aafb1 (diff)
Episode 4: Slides
-rw-r--r--README.md46
-rw-r--r--main.c35
-rw-r--r--main.js7
3 files changed, 68 insertions, 20 deletions
diff --git a/README.md b/README.md
index 5a4e8ec..85092c9 100644
--- a/README.md
+++ b/README.md
@@ -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:
diff --git a/main.c b/main.c
index ad5174c..83bf64d 100644
--- a/main.c
+++ b/main.c
@@ -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);
+}
diff --git a/main.js b/main.js
new file mode 100644
index 0000000..949b379
--- /dev/null
+++ b/main.js
@@ -0,0 +1,7 @@
+function main() {
+ let person = { age: 30 };
+
+ function slide(person) {
+ person.age = 100;
+ }
+}