Thinking in C
Foundations for Java and C++
by Chuck Allison
© 2000 MindView, Inc. http://www.MindView.net

Note: Please click here if you haven't performed the installation. Please read the license agreement.

 
Table of Contents
Chapter 1: Introduction and Getting Started
           Chapter 1 Exercises
Chapter 2: Fundamental Data Types
           Chapter 2 Exercises
Chapter 3: Operators
           Chapter 3 Exercises
Chapter 4: Controlling Program Flow
           Chapter 4 Exercises
Chapter 5: Compound Data Types
           Chapter 5 Exercises
Chapter 6: Programming with Functions
           Chapter 6 Exercises
Chapter 7: Pointers 101
           Chapter 7 Exercises
Chapter 8a: A first look at Java (if you're going on to Java)
           Chapter 8a Exercises
Chapter 8b: Pointers 102 (if you're going on to C++)
           Chapter 8b Exercises
(There is no "Chapter 9a", since it is not necessary for Java)
Chapter 9b: A first look at C++
           Chapter 9b Exercises
Where to go next ...
Source code from examples, exercises and solutions
Thinking in C++, 2nd Edition book resources
Thinking in Java electronic book
Compilers
Troubleshooting
 

Chapter 1: Introduction and Getting Started
40 Minutes and 16 seconds
Start Lecture
Back to Table of Contents

This chapter gives the context for the course (including the level of programming that you should already have) and clarifies course objectives (that is, to find the shortest, most effective path to Java and C++). We take a first look at C programming by examining statements, comments, include files, and standard Input/Output (I/O).


Chapter 1 Exercises

Compile and execute two sample programs. (A full description is given at the end of the Chapter 1 lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
first.c avg.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
avg.out

Back to Table of Contents

 

Chapter 2: Fundamental Data Types
40 Minutes and 25 seconds
Start Lecture
Back to Table of Contents

Like most languages, C has two flavors of numeric data types: integers and real numbers. Unlike many languages, they come in an array of different sizes. This chapter explores the limits and behavior of C's built-in types and explains converting from one type to another both implicitly and explicitly (i.e., with casting).


Chapter 2 Exercises

In this exercise you will learn to round to the nearest integer. (A full description is given at the end of the Chapter 2 lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
float.c limits.c missing.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
lab2.c

Back to Table of Contents

 

Chapter 3: Operators
21 Minutes and 22 seconds
Start Lecture
Back to Table of Contents

C has more operators than most languages. Most of these operators are binary operators, some are unary, and there's even a ternary operator (a what? :-). Since C is ­- among other things -- a systems language, there are operators that access features close to the machine. In this chapter we cover all but five operators (those five are covered in later chapters). You'll also see the way operators work together.


Chapter 3 Exercises

In this exercise you'll learn to test the parity (i.e., even-ness/odd-ness) of input numbers. (A full description is given at the end of the Chapter 3 lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
bitwise.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
lab3.c

Back to Table of Contents

 

Chapter 4: Controlling Program Flow
23 Minutes and 48 Seconds
Start Lecture
Back to Table of Contents

In 1968 a pair of mathematicians proved that all algorithms could be expressed by three simple mechanisms, coupled with an arbitrary number of boolean (logical) flags:

  1. Sequences of statements
  2. Decision-making
  3. Repetition

This chapter shows how to use these in C, and then some.


Chapter 4 Exercises

In this exercise, you will repeat the exercise from Chapter 3 on an arbitrarily large number of integers. (A full description is given at the end of the Chapter 4 lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
age.c age2.c branch.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
lab4.c lab4a.c

Back to Table of Contents

 

Chapter 5: Compound Data Types
35 Minutes and 19 Seconds
Start Lecture
Back to Table of Contents

You can only go so far with numbers. Programming gets interesting when you create complex data types from simpler ones. This chapter discusses arrays (in all dimensions!), illustrates text processing with character strings, and shows you how to create complex data types of your own.


Chapter 5 Exercises

In this exercise you will create and process a collection of employee records. (A full description is given at the end of the Chapter 5 lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
2d.c 3d.c 3d2.c reverse.c strings.c struct.c struct2.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
lab5.c

Back to Table of Contents

 

Chapter 6: Programming with Functions
40 Minutes and 38 Seconds
Start Lecture
Back to Table of Contents

Functions are the building blocks of real-world C programs. Here you'll learn about value semantics, the void type, function prototypes, and the scope (visible region) of identifiers. You'll also come to understand storage class, modularity, and information hiding, which is a key principle of object-oriented programming.


Chapter 6 Exercises

In this exercise you will divide the employee program into modules, separating interface from implementation. (A full description is given at the end of the Chapter 6 lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
employee.h file1.c file2.c fun1.c fun2.c fun3.c lab6.c scope.c stack.c stack.h static.c tstack.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
employee.c employee.h lab6.c

Back to Table of Contents

 

Chapter 7: Pointers 101
44 Minutes and 55 Seconds
Start Lecture
Back to Table of Contents

Pointers are essential for effective systems programming and for implementing complex objects in C++. But if you're going on to Java, you don't need all that machinery. However, you do need some basics because even Java uses pointers (but in a much more restricted way). This chapter gives a minimum coverage of pointers so that you can move on to Java: indirection, reference semantics, and using the heap (dynamic memory).


Chapter 7 Exercises

In this exercise, you will modify the employee program to handle dynamic employee records. (A full description is given at the end of the Chapter 7 lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
echo.c employ2.h indirect.c lab7.c reverse2.c structarg.c swap.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
employ2.c employ2.h lab7.c

Back to Table of Contents

 

Chapter 8a: A first look at Java
46 Minutes and 27 Seconds
Start Lecture
Back to Table of Contents

You made it! If you're not interested in C++, this is your final stop. Here we look at how Java programs are written and built, and more importantly, how the Java Runtime Environment works. We also look at control flow and how to create objects and arrays.


Chapter 8a Exercises

In this exercise you will implement a simple Stack class (first seen in Chapter 7) using Java. (A full description is given at the end of the Chapter 8a lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
Array1.java Array2.java Array3.java Average.java Employee.java Hello.java Label.java Limits.java Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
Stack.java

Back to Table of Contents

 

Chapter 8b: Pointers 102
1 Hour, 19 Minutes and 28 Seconds
Start Lecture
Back to Table of Contents

If you're planning to tackle C++, you're not done yet! First you have to become familiar with multiple levels of pointer indirection, pointer arithmetic, making objects read-only via const, generic pointers (void*), and the relationship pointers have with arrays and functions.


Chapter 8b Exercises

In this exercise, you will:

  1. Write a function that inspects any object.
  2. Totally hide the Employee implementation in an incomplete type.
  3. Define and use a pointer within a 4-dimensional array (optional, but recommended!).

(A full description is given at the end of the Chapter 8b lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
bitwise2.c fptr.c fptr2.c parith.c parray.c pptr.c qsort.c stack8b.c stack8b.h ulimits.c Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
employ2.c employ2.h lab8-1.c lab8-2.c lab8-3.c

Back to Table of Contents

 

Chapter 9b: A first look at C++
36 Minutes and 29 Seconds
Start Lecture
Back to Table of Contents

Relax, it's all downhill from here (until you take your full-blown C++ class :-)! This chapter explains key differences between C and C++, and takes you through three essential C++ features:

  1. Type safety
  2. Classes
  3. Templates

Also covered are IOStreams and the free store operators new and delete.


Chapter 9b Exercises

In this exercise, you will implement a complete Employee class. (A full description is given at the end of the Chapter 9b lecture.)

Here are the source-code files for the exercises (use these as a starting point for solving the exercises):
hello.cpp intstack.cpp intstack.h stack9b.h tintstack.cpp tstack9b.cpp Other options for source code

Start Lecture

Here are the source-code files for the exercise solutions:
employee.cpp employee.h lab9.cpp

Back to Table of Contents

 

Where to go next ...

Now that you have enough of an understanding of C, you're ready to move on to your new language of choice: C++ or Java. MindView, Inc. has more resources available for you to learn these languages, including a variety of seminars, training CD Roms like this one, and both of Bruce Eckel's award-winning, freely downloadable books Thinking in C++ and Thinking in Java (available on this CD, see here). Be sure to visit http://www.MindView.net to download your copies of the books, and to learn about the other seminars and CDs!

Back to Table of Contents

 

Source Code
Back to Table of Contents

You have several options for accessing the source code for all the slides, exercises and solutions. The hyperlinks shown above for all the files in each chapter go to HTML files which can be cut and pasted directly from your browser into your editor or compiling environment. This is a bit tedious, but it works.

All the code files are also available in each chapter's subdirectory on this CD ROM. For each chapter, there's a subdirectory called "Code" which contains the source code files.

The most convenient form is a ZIP file containing all the source code, which can be copied directly to your hard disk and unzipped; the unzipping process will create all the appropriate files and directories. If you don't have an "unzip" program on your machine, the best place to go for tools is http://www.cdrom.com/pub/infozip/. This is a freeware, open-source implementation of zipping and unzipping programs that work on virtually all platforms. This CD ROM contains a version of INFO-ZIP for 16 & 32 bit DOS and for the Macintosh, in the subdirectory Info-Zip. Here are the readme files for dos and the Macintosh.

All questions about INFO-ZIP should be directed to the creators of that program; the INFO-ZIP material is only being included as a convenience and is not an official part of the Thinking in C CD Rom. Info-ZIP's software (Zip, UnZip and related utilities) is free, and can be obtained as source code or executables from Internet/WWW sites, including http://www.cdrom.com/pub/infozip/).

Please note: when unzipping (using the above program) for Unix/Linux platforms, remember to use the -a flag, which will correct all the CR/LF issues during the unzipping process. The presentation slides and multimedia on this CD do NOT work on Unix/Linux.


Thinking in C++, 2nd edition book resources
Back to Table of Contents

This CD Rom also includes electronic versions of the book Thinking in C++, 2nd edition, Volume 1 and source code for the book. Click here to go to the directory containing the versions of the book.

Thinking in Java book

This CD Rom also includes an electronic version of the book Thinking in Java, 2nd edition and source code for the book. Click here to go to the directory containing the versions of the book.


Compilers
Back to Table of Contents

This CD Rom does not include any compilation tools for C, C++ or Java. It is your responsibility to acquire and install the tool of your choice. See here for more details.

 

Troubleshooting
Back to Table of Contents

If you have a problem you cannot resolve, please first look at the FAQ.