This is a six session course covering the basics of C, a simple, powerful,and widely-used programming language.
If you don't have the time for a series of classes on C, SIPB is also offering a three-hour course that covers less material.
| DAY | TOPICS | PITFALLS |
|---|---|---|
| Monday 15 January |
Overview. Background. Program structure (hello.c). Atomic types. Statements, expressions, and operators. Formatted input and output: printf and scanf. if...else. Logical operators. Assignment | Assignment is not equality. scanf takes a pointer. Avoid dangling else clauses. |
| Wednesday 17 January |
Code blocks. Statements. Operators. Conditionals if () {} else {}. Iteration: while, do... while. and for and using break and continue. Assignment. |
Use longs to avoid overflow. Comment loops with invariants. Don't follow for or while with a semicolon unless you mean it. In a macro definiton, parenthesise everything, and avoid side effects. |
| Monday 22 January | Fancy conditionals using switch, case, default. The preprocessor. Basic data types. More data types; enums, structs, and unions. Function declaration. Scope and storage classes; global, extern, static, and local, register. Assignment |
Terminate cases with breaks. Return types default to int, so remember to include header files. |
| Wednesday 24 January |
Typedefs. Pointers. Casting. Assignment. | Don't return a pointer to a local auto. Casting is an unsafe operation with no checking. There is no bounds checking for arrays. Arrays are not the same as pointers. |
| Monday 29 January |
Arrays. Strings. Review of pointers. Dynamic memory allocation. Multidimensional Arrays. Pointers to functions. Here's a few programs we wrote in class: C Keyword Search. Rough Sorting Algorithm. Binary Tree search for word occurrences. Assignment. | Pointer subtraction is different from the results of a sizeof()operator. 2 Dimensional Arrays are not the same as an Array of Pointers which is not the same as a Pointer to a Pointer. Declaring a pointer to a function. Pointers to functions are not always the same size as other pointers. |
| Wednesday 31 January |
Standard Libraries. Variable Argument Lists. Using argc, argv and envp. Writing code that can't be read. Special topics in C. |
gcc -g -Wall -Werror -o programname codefile
zctl add ccc \* \*
To send a message to the class, zwrite to class (-c) ccc with an instance (-i) appropriate to the topic. Here is an example:
zwrite -c ccc -i printf
Type your message now. End with control-D or a dot on a line by itself.
What is the format specifier for a decimal integer?
^D