General Concepts
- Compiled vs. interpreted languages (e.g., C++ vs. Python)
- Compiling and Linking
- Invoking the C++ compiler
Basic Syntax
- Legal identifiers
- Allowable characters, case sensitivity
- Rules vs. conventions
- Literals
- Numerical literals (e.g., 1, -5.5)
- String literals (e.g., "Hello, world\n")
- Character literals (e.g., 'A')
- Constants
- Defining using "#define PI 3.14"
- Defining using "const double PI=3.14;"
- Variable Declaration
- Basic format
- Where it can appear
- What "scope" is
- Local variables vs. global variables
- Declaring (or re-declaring) variables in a nested block: nested scope
- Are local variables automatically initialized?
- Basic types in C++
- int, float, double, char, bool
- What is difference between short, int, and long? float and double?
- Operators:
- Arithmetic
- Relational
- Logical (boolean)
- Assignment
- Binary vs. unary operators
- Ternary operator (, e.g. "x == y ? equals++ : equals-- ;")
- Shorthand operators: x++, x--, x += y, x*= y, etc.
- Precedence and associativity
- Expressions, statements
- Type conversion
- In arithmetic operators: e.g. int + double
- in assignment: int x = 5.5;
- Using casts (e.g. "(double) x" or "static_cast<double>x"
- Single statements vs. statement blocks (a.k.a. compound statements)
- Using curly braces: "{...}"
- Comments: "/*...*/", and "//"
- Pitfalls:
- "=" vs. "=="
- forgetting {} with conditional or loop
- loop and array bounds
Console input/output
- cin, cout, cerr
- #include <iostream>
- <<, >> operators
Control Flow
- Conditionals
- Syntax of "if/then/else" statements
- Interpretation of ints as true/false (e.g., is -1 "true"?)
- What does "int x - true" do? What about "bool b = (2 > 1)"?
- Switch statements (essentially a fancy type of conditional)
- Loops
- while(x) { ... }
- do { ... } while (x);
- "for" loops
- break, continue
Minimal Program:
-
Should be able to write a simple "Hello, world" program from
scratch
The C++ Preprocessor
- #define — what this directive does
-
#ifdef/#ifndef/#endif — what these directives do and how
they are used to "guard" a header (.h) file
Program file structure:
- Difference between .h and .cpp files
- How header file includes work:
- #include -- what this directive does
- Why do we "guard" header files?
Functions
- Syntax for declaring a function (a.k.a. "function prototype")
- Syntax for defining a function
- Syntax for calling a function
- Declaring return type
- Declaring formal parameters
- Difference between parameters and arguments
- You should be able to write a simple function from scratch
Function Parameters
- Parameters vs. arguments
- Call-by-value vs. call-by-reference
- Syntax for each
- Difference between the two
-
What happens in each case when you reassign a value to a
parameter inside the function?
-
You should be able to write a simple swap() function that
exchanges the actualy parameter variables so that caller is
affected.
- "const" parameters: (e.g. "void Foo(const int x) { ... }"
- What does declaring a parameter to e "const" do?
Arrays
- How to declare local variable as an array
- Initializing arrays
- How are C-strings represented? Array-of-chars...
- How are arrays stored?
- Accessing array elements: using "x[pos]" indexing
- How to declare as parameter in function declaration/definition
- Are array arguments to function calls passed by-value or by-reference?
Basic Pointers:
-
How to declare a pointer (e.g. "int *xPtr" to declare xPtr as
"pointer to int")
- How to get the address of another variable (e.g. "xPtr = &myInt")
- Using pointers to simulate call-by-reference
- Pointer arithmetic: what would "*(xPtr + 1) = 0" do?
- "*" (dereference) and "&" (address of) operators
- Use of new, delete, and delete []
Structures
- What are they?
- How to define one
- How to use one
Basic Classes
- What is a class?
- Difference from a struct
- Class "interfaces"
- Encapsulation / Abstract Date Type
- What is benefit of keeping implementation details from user?
- Syntax for defining a class
- Data members and function members
- private versus public members
- Accessors, mutators, facilitators
- Where/how to define member functions
- Constructors:
- What is the purpose of a constructor?
- Default vs. non-default constructors
- Initialization lists for constructors
- Aggregation:
- Including classes (actually, class isntances) inside other classes
- Why would you do this?
Makefiles
- What are targets, dependencies, and recipes?
- Why do we separate compilation and linking?
- Be able to complete a simple makefile.