about summary refs log tree commit diff stats
path: root/org
diff options
context:
space:
mode:
authorelioat <hi@eli.li>2022-11-26 20:44:59 -0500
committerelioat <hi@eli.li>2022-11-26 20:44:59 -0500
commit2f4c578507a371caa7bba18d6d7104cb2d39182c (patch)
treeefe62851846a9a972741692c902010a5830ea1aa /org
parentd9bf844148e0ca641c0894215c6afa0604229dc8 (diff)
downloadhard-way-2f4c578507a371caa7bba18d6d7104cb2d39182c.tar.gz
*
Diffstat (limited to 'org')
-rw-r--r--org/c/ex_01.org7
-rw-r--r--org/c/ex_03.org47
-rw-r--r--org/c/ex_04.org15
-rw-r--r--org/c/ex_05.org80
4 files changed, 146 insertions, 3 deletions
diff --git a/org/c/ex_01.org b/org/c/ex_01.org
index d479a84..fd6f685 100644
--- a/org/c/ex_01.org
+++ b/org/c/ex_01.org
@@ -1,9 +1,12 @@
 * Exercise 1.
 
+This isn't my first rodeo, so I won't be breaking everything down.
+
+My aim doing this using org-mode in a literate style is to produce some sort of useful documentation for myself, something like a cookbook.
 
 #+BEGIN_SRC C
   #include <stdio.h>
-
+  /* comments for fun and proffit */
   int main(int argc, char *argv[])
     {
       int distance = 100;
@@ -16,5 +19,3 @@
 
 #+RESULTS:
 : you are 100 miles away.
-
-Big notable bits from this are the ~#include~.
diff --git a/org/c/ex_03.org b/org/c/ex_03.org
new file mode 100644
index 0000000..b889a2c
--- /dev/null
+++ b/org/c/ex_03.org
@@ -0,0 +1,47 @@
+* Exercise 3
+
+#+BEGIN_SRC C
+    #include <stdio.h>
+
+  int main()
+    {
+      int age = 10;
+      int height = 72;
+
+      printf("I am %d years old.\n", age);
+      printf("I am %d inches tall.\n", height);
+
+      return 0;
+    }
+#+END_SRC
+
+#+RESULTS:
+| I | am | 10 | years  | old.  |
+| I | am | 72 | inches | tall. |
+
+** printf conversion specifiers
+
++ %%,	Print a single % character
++ %c,	Convert an int to an unsigned character and print the resulting character
++ %d or %i,	Print an int as a signed decimal number
++ %u,	Print an unsigned as an unsigned decimal number
++ %o,	Print an unsigned as an unsigned octal number
++ %x,	Hexadecimal notation (using lowercase letters a-f)
++ %X,	Hexadecimal notation (using uppercase letters A-F)
++ %e,	Exponential notation (using a lowercase e as in 3.1415e+00)
++ %E,	Exponential notation (using an uppercase E as in 3.1415E+00)
++ %f,	Print a double using a decimal format like [-]ddd.ddd
++ %g,	The more compact of %e or %f, insignificant zeros do not print.
++ %G,	Same as g, but using an uppercase E
++ %s,	Print the string pointed to by a char *
++ %p,	Print a void * argument in hexadecimal (ANSI C only)
++ %n,	Store the number of characters printed at this point in the integer pointed to by the int * argument. Nothing is printed. (ANSI C only).
+
+** printf escape sequences
+
++ \n,	prints a new line
++ \b,	backs up one character
++ \t,	moves the output position to the next tab stop
++ \\,	prints a backslash
++ \",	prints a double quote
++ \',	prints a single quote
diff --git a/org/c/ex_04.org b/org/c/ex_04.org
new file mode 100644
index 0000000..d287dca
--- /dev/null
+++ b/org/c/ex_04.org
@@ -0,0 +1,15 @@
+* Exercise 4
+
+Debuggers, baby!
+
+#+BEGING_SRC plaintext
+gdb --args // this flag allows you to pass arguments *through* gdb
+           // into a program, without this flag gdb assumes any
+           // passed arguments are for it
+
+gdb --batch --ex r --ex bt --ex q --args
+// run the program so that if it fails you get a backtrace
+#+END_SRC
+
+Sometimes you have lldb instead of gdb. They are similar, but slightly different -- brace yourself for this.
+
diff --git a/org/c/ex_05.org b/org/c/ex_05.org
new file mode 100644
index 0000000..799712f
--- /dev/null
+++ b/org/c/ex_05.org
@@ -0,0 +1,80 @@
+* Exercise 5
+** Operators
+*** arithmetic operators
+| operator | description |
+|----------+-------------|
+| +        | add         |
+| -        | subtract    |
+| *        | multiply    |
+| /        | divide      |
+| %        | modulus     |
+| ++       | increment   |
+| --       | decrement   |
+
+*** relational operators
+| operator | description        |
+|----------+--------------------|
+| ==       | equal              |
+| !=       | not equal          |
+| >        | greater than       |
+| <        | less than          |
+| >=       | greater than equal |
+| <=       | less than equal    |
+
+*** logical operators
+Logical operators perform logic tests. They weirdest one is the [[https:www.freecodecamp.org/news/c-ternary-operator/][ternary operator]].
+
+The ternary operator is sort of like a different way to write an if/else statement.
+
+#+BEGIN_SRC plaintext
+condition ? value_if_true : value_if_false
+#+END_SRC
+
+| operator | description     |
+|----------+-----------------|
+| &&       | logical and     |
+| ||       | logical or      |
+| !        | logical not     |
+| ? :      | logical ternary |
+
+*** bitwise operators
+Bitwise operators are the weirdos, and the ones you don't often encounter in other languages...or like, in JavaScript, I guess. They alter bits directly. They are useful when working in low-level systems.
+
+| operator | description              |
+|----------+--------------------------|
+| &        | bitwise and              |
+| |        | bitwise or               |
+| ^        | bitwise xor              |
+| ~        | bitwise one's complement |
+| <<       | bitwise shift left       |
+| >>       | bitwise shift right      |
+
+*** assignment operators
+Assignment operators assign expressions to variables.
+
+| operator | description              |
+|----------+--------------------------|
+| =        | assign equal             |
+| +=       | assign plus-equal        |
+| -=       | assign minus-equal       |
+| *=       | assign multiply-equal    |
+| /=       | assign divide-equal      |
+| %=       | assign modulus-equal     |
+| <<=      | assign shift-left-equal  |
+| >>=      | assign shift-right-equal |
+| &=       | assign and-equal         |
+| ^=       | assign xor-equal         |
+| |        | assign or-equal          |
+
+*** data operators
+These deal with aspects of pointers, member access and various other data structures in C.
+
+| operator | description           |
+|----------+-----------------------|
+| sizeof() | get the size of       |
+| []       | array subscript       |
+| &        | the address of        |
+| *        | the value of          |
+| ->       | structure dereference |
+| .        | structure reference   |
+