Experimental C/C++ Curriculum
The hit with a textbook approach™ - 2017
By Alæstor, of the Future Gadget Lab
Contact via the Public Discord Server
This is just a list of talking points. A linear guide to be used by the teacher.
These are shorthand notes and reminders. NOT to be read verbatim.
The order isnt set in stone, presentation, examples, and exercises should be made ahead of time
CONCEPTS
-
What is data?
1's and 0's - data is information we care about.
-
Intro to the Ideal Memory Model
the concept of data being stored in memory at certain addresses.
-
What is Executable Code
An ordered list of instructions the computer will run.
-
What is a Function
A section of executable code which can be "called". When a function is called, the computer begins to read from the start of the function's executable code. Functions can interact with data by "passing in arguments" as inputs to a function being called, and the called function can return an output.
-
What is a Program
Executable code, loaded into memory.
A program file designates an "entry point". A function where your program begins. Where the computer starts reading first. Usually named "main()". -
What are Programming Languages (optional)
Languages are human-readable abstractions of machine instructions. A literal language we use to describe the behavior we wish the program to do. The level of abstraction determines how "high" or "low" level a language is. For example, ASM (assembly) is a 1:1 representation of the instructions being run on the CPU of a computer. C abstracts that higher into a form we can more easily work with and allows us to express the behavior we want in a more simplistic / human readable terms.
-
What are Variables
Allocated storage in memory for holding values. They have "types" which determine their behavior in code, and the length of memory used to store data. When you use a variable, it gets its value from the starting memory address of where it's stored.
Basic types (short, int, long long, bool, float, double, char)
Type modifiers (const, unsigned)
declaration, assignment, and initialization. -
How a variables value is represented in memory (optional)
Introduction to number systems
Binary vs. Decimal vs. Hex
Bits and bytes
(bits^2) is how many unique states that amount of bits can represent
(2^bits-1) is the maximum possible decimal value that can be stored (-1 because 0)
("bits" is the number of bits you have available for information storage)'A' resolves to whatever value represents the character A.
signed / unsigned integer, and why unsigned can hold a much bigger number.
floating point is weird because math -
The Pre-Processor
include copy+paste
header-guard -
disclaimer
printf() is a function we're going to be using. It's provided by the standard library, and included via stdio. How it actually works will be explained later. we're going to use it so we can see the values contained in certain variables.
PRACTICAL EXAMPLES
-
Declaring a Function and Passing Values
explain return type, show declaring parameters / what it accepts.
declaration vs. definition.
scoping"return" keyword.
example, making a simple function, preferably some math thing.
-
LValues and RValues
LValues are things like variables which are addressable.
RValues are "temporary", like the result of an expression, or a hard-coded literal integer -
Logic Flow
cpp
"condition" is boolean.if(condition) statement;
while (condition) statement;
do {statement} while (condition);
for (initializer; condition; incrementor) statement;Comparison operators ( ==, != , >, <, >=, <=, &&, || )
-
References
a variable that represents another variable, accessing the same memory and hence data stored there.
type& name = var;example, a function that takes input and increments/decrements it
also reference to RValues (T&& var) -
Pointers
a variable that contains an address as its value.
a pointer is just an address, but the type determines its behavior.
&var resolves to the address of var's value.
type *name = &var;- dereferencing
void pointer
char pointer and aliasing
nullptr keyword
layering pointers
"raw" and smart pointers
- dereferencing
-
Arrays
values in contiguous memory
declaration
initialization
indexingconcept of buffer overflow, protecting against it.
how arrays are pointers and introduction to pointer arithmetic. -
Conventional String
an array of characters with a null-terminator at the end
"double quotes" (string literal) resolves to an address of a null terminated string.
revisiting the behavior of printf() and how / why it parses the string. -
Structures
struct as a type.
separate variables in contiguous memory.
accessing members.
accessing structures in structures.pointers to structures
-> structure indirect syntax -
Unions
differing types, memory.
explain type-punning, explain why you shouldn't do it.
provide "real world" example of "bool ipv4" and a union of ipv6 and ipv4 -
Classes and methods
private, public
protected and class inheritance -
Templates
function templates
class templatesexplain generated exclusivity (X<y> != X<z>)