diff --git a/02_fundamentals/Makefile b/02_fundamentals/Makefile index 3449c17bbd284eecec1890b4401abad8998ff222..1059496712db138123ca83caaa6dc06e4aa71e36 100644 --- a/02_fundamentals/Makefile +++ b/02_fundamentals/Makefile @@ -5,21 +5,21 @@ CXX = g++ CFLAGS = -Wall -O3 .PHONY: all -all: control_structures functions basic_types +all: basic_types control_structures functions # Here I'm using some of Make's built in variables: $@ and $<. The former gets substituted with the # name of the target. In this case, that's "loops". The latter gets substituted with the first # prerequisite. In this case, that's "loops.c". These are hard to remember, but can save you some # typing if you decide to rename things. -control_structures: control_structures.c +basic_types: basic_types.c $(CC) $(CFLAGS) -o $@ $< -functions: functions.c +control_structures: control_structures.c $(CC) $(CFLAGS) -o $@ $< -basic_types: basic_types.c +functions: functions.c $(CC) $(CFLAGS) -o $@ $< .PHONY: clean clean: - rm -f control_structures functions basic_types + rm -f basic_types control_structures functions diff --git a/02_fundamentals/README.md b/02_fundamentals/README.md index f737b035cacf363463339843cd43f546567c23ee..e7ee74a06c4a5a4eadba6c1bec3786f22e9b7645 100644 --- a/02_fundamentals/README.md +++ b/02_fundamentals/README.md @@ -1,13 +1,56 @@ -# Control Structures +# Fundamentals -These examples demonstrate loops and functions. +These examples demonstrate C's basic types, how to use control structures like branches and loops, +and how to write functions. ``` -demo@linux:02_control_structures$ make -gcc -Wall -O3 -o loops loops.c +demo@linux:02_fundamentals$ make +gcc -Wall -O3 -o basic_types basic_types.c +gcc -Wall -O3 -o control_structures control_structures.c gcc -Wall -O3 -o functions functions.c +``` + +``` +demo@linux:02_fundamentals$ ./basic_types +Signed Integers +min: -2147483648 +max: 2147483647 +5 - 10 = -5 + +Unsigned Integers +min: 0 +max: 4294967295 +5 - 10 = 4294967291 + +Floating Point +min: -3.402823e+38 +smallest positive (normalized): 1.175494e-38 +max: 3.402823e+38 +closest float to 1.2: 1.2000000477 +1.2 - 0.2: 1.0000000477 +(0.001 + 1.0) - 1.0 = 0.001000047 +0.001 + (1.0 - 1.0) = 0.001000000 + +Double Precision Floating Point +min: -1.797693e+308 +smallest positive (normalized): 2.225074e-308 +max: 1.797693e+308 +closest double to 1.2: 1.19999999999999996 +1.2 - 0.2: 1.00000000000000000 +(1e-6 + 1.0) - 1.0 = 0.000001000000000000024 +1e-6 + (1.0 - 1.0) = 0.000001000000000000000 -demo@linux:02_control_structures$ ./loops +Character +1$ +numeric 0 (won't show up as anything): +ASCII 0: 0 + +Strings +hello +``` + +``` +demo@linux:02_fundamentals$ ./control_structures while loop: 0 while loop: 1 while loop: 2 @@ -25,7 +68,9 @@ leaving the while loop 1 is odd 3 is odd i is 42 +``` +``` demo@linux:02_control_structures$ ./functions two is even three is odd diff --git a/README.md b/README.md index 85d681a0115c3047e489aecabe6b069ee7dde5c0..c41a081a3ade1f141fe15419baea80666abd9042 100644 --- a/README.md +++ b/README.md @@ -49,4 +49,5 @@ On Windows... honestly I'm not sure. I haven't set up a development environment ## Examples - [hello world](./01_hello_world) -- [control structures](./02_control_structures) +- [fundamentals](./02_fundamentals) +- [inputs and outputs](./03_inputs_and_outputs)