C++ Crash Crash Course
Day 1
main function
g++ source1.cpp -o program1
Paths, . and .. in navigating directories
data type - memory, binary
declare variables (int, char, string as series of chars)
statements end with semicolon
cstdio library include
calling a function - printf
if condition block else block (example: do something different based on argc)
for loop - 3 statements (initialiser, condition, post-loop advancement) and a code block
Homework: study "while" loop and "switch" statement
Day 2
While loop - condition and 1 code block.
Do while loop - code block then condition.
While loop = for loop with empty initialiser/advancement statements
Switch - match expression's result to case label
Switch vs if-else differences.
your own function
calling with parameters copied as separate set of var values in function
classes as blueprints.
complex var data type - instances of a class all have the same set of fields
the "." field accessor (var1.func1() etc)
each instance have it's own separate memory for storing data.
Example code - fibonacci sequence.
Value overflow because not enough number of bits to represent large numbers.
Homework: implement factorial (1 to 20) calculator
Day 3
factorial printer - 2 approaches:
- for-loop that goes 1 to 20 and each loop calls fact
function and prints return.
- for-loop that goes 1 to 20 and multiplies once each time and print.
set initial values of vars when declaring otherwise initial values are unpredictable