SIPB
SIPB IAP 2007


Crash Course in C

Leaders:
Michael Shaw
Christian Ternus
Email:
sipb-iap-c@mit.edu
Description:
A series of six two-hour classes that will cover the fundamentals of programming in C.
Class Schedule:
Mon, Wed, Jan 15, 17, 22, 24, 29, 31, 02-04:00pm
Location:
35-225
Suggested Background or Preparation:
6.001 or other experience with a high-level language

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.


APPROXIMATE SCHEDULE OF TOPICS
DAY TOPICS PITFALLS
Monday
15 January

Day 1 Slides

Day 1 Notes

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

Day 2 Slides

Day 2 Notes

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

Day 3 Slides

Day 3 Notes

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

Day 4 Slides

Day 4 Notes

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

Day 5 Slides

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

Day 6 Slides

Day 6 Notes

Standard Libraries. Variable Argument Lists. Using argc, argv and envp. Writing code that can't be read. Special topics in C.

Texts:


Other Notes:


Compiling


Getting Help:


Places to go from here:


Email: sipb-iap-c@mit.edu