Thinking in C: Foundations for Java & C++
by Chuck Allison
Creative Commons License
Play "A Study in C," by Carcassi,
performed by Chuck Allison

Chapters:   1    2    3    4    5    6    7    8a    8b    9b

Hello! I'm Bruce Eckel, and I have worked with Chuck Allison to bring you this Flash™-based seminar, which is being published by my company, MindView, Inc., as a way to prepare you for the following Prentice Hall books:

Link to Thinking in Java book page Link to Amazon
Link to Thinking in C++ book page Link to Thinking in C++ book page

Chuck and I believe that this learning experience will provide you with great value on your educational journey.

This seminar will give you a background in the fundamentals of C syntax, to prepare you to move into Java or C++. You'll also find it useful even if you would just like an introduction to C.

Please note that we are assuming you have already written at least a few small programs in some programming language. You might still get some value from the seminar even if you've never programmed before, but that could require some extra effort at the beginning. You'll know by the end of the first lecture and exercises.

All the lectures in the seminar are self-explanatory, and the first one describes what to expect throughout the course.

This seminar is licensed under the Creative Commons "Attribution-NonCommercial-NoDerivs 2.5" license, which means that you may freely distribute the entire package as long as you give attribution to the authors, but you may not sell it or modify it. See the link above for more detail.


Using this Seminar

Clicking on the "Start Lecture" link for each chapter or solution will open a web page containing various Flash components. You can resize your browser window and the components will resize themselves to fit.

If you do nothing, the first slide will load and the narration will play, then the next slide, etc., until the lecture is complete. After the last slide finishes you will automatically be returned to this page.

On the left you'll see a list of slide titles; clicking on any title will take you to that slide and begin playing the narration.

On the bottom you'll see a progress bar with an indicator showing how far the narration has progressed. If you hover the mouse over the bar it will expand into a controller that allows you to move the narration forward or backward, and to adjust the sound level.

The last title in the list of slide titles is named "Return to Index." Clicking on that title will return you to this page at any time. You'll also return to this page automatically after the narration on the last slide finishes.


Chapter 1: Introduction and Getting Started
40 Minutes
Start Lecture

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). You may need to refer to the compilers section to find and install the appropriate C compiler.

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

Start Lecture

Here is the file showing the output of the exercises: avg.out


Chapter 2: Fundamental Data Types
41 Minutes
Start Lecture

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

Start Lecture

Here is the source-code file for the exercise solution: lab2.c


Chapter 3: Operators
22 Minutes
Start Lecture

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 is the source-code file for the exercise (use this as a starting point for solving the exercise): bitwise.c

Start Lecture

Here is the source-code file for the exercise solution: lab3.c


Chapter 4: Controlling Program Flow
24 Minutes
Start Lecture

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

Start Lecture

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


Chapter 5: Compound Data Types
35 Minutes
Start Lecture

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

Start Lecture

Here is the source-code file for the exercise solution: lab5.c


Chapter 6: Programming with Functions
41 Minutes
Start Lecture

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

Start Lecture

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


Chapter 7: Pointers 101
45 Minutes
Start Lecture

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

Start Lecture

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


Chapter 8a: A first look at Java
47 Minutes
Start Lecture

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.) You may need to refer to the compilers section to find and install the appropriate Java compiler.

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

Start Lecture

Here is the source-code file for the exercise solution: Stack.java


Chapter 8b: Pointers 102
1 Hour, 20 Minutes
Start Lecture

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

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


Chapter 9b: A first look at C++
37 Minutes
Start Lecture

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.) You may need to refer to the compilers section to find and install the appropriate C++ compiler.

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

Start Lecture

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


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, Flash-based training seminars like this one, and both of Bruce Eckel's award-winning, freely downloadable books Thinking in C++ and Thinking in Java (the first through third editions of Thinking in Java are available as electronic downloads).

Bruce Eckel also provides live seminars, consulting, and technical events on various topics, which you can learn about by visiting the MindView, Inc. Web site.


Source Code

The hyperlinks shown above for all the files in each chapter connect 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 under the subdirectory called code, where you will find a subdirectory for each chapter (this is the same directory where that chapter's HTML files are stored).


Compiling code

To compile the example/exercise/solution code for this seminar, you will need to acquire and install compilers for C, C++ and Java.

Keep in mind that the installation and use of free compilers can sometimes be more complex than for those that you purchase, so be ready to roll up your sleeves and struggle a bit to get them going the first time (unfortunately, we are unable to provide support assistance with compiler installations. Please refer to the site where you downloaded the compiler or the compiler vendor for such support).

C & C++: There are a number of different C and C++ compilers that are freely-available on the Internet (A C++ compiler will be fine for compiling C code). You should go to your favorite Web search engine, such as Google, and look for "Free C++ Compilers" or something similar. For example, you can find a free 32-bit C++ compiler for Windows at www.Borland.com. Also, The 32-bit DOS/Windows version of the GNU g++ compiler comes as part of Cygwin (this is especially helpful if you're used to Unix/Linux).

Java: Download the free JDK Java compilation system from http://java.sun.com. It's the standard and it has lots of documentation with it, in HTML form (the documentation is a separated download, from the same site).


Comments & Suggestions

Send .


Credits

Course development, slide creation and recording: Chuck Allison, www.FreshSources.com.

Sound Engineering: Sharlynn Cobaugh

Production: Bruce Eckel

Graphic Design: Daniel Will-Harris

Thanks to the folks at Macromedia/Adobe, for creating Flex, FlexBuilder, and providing me with technical support.

Special thanks to FlashSpring for their PPT-to-SWF conversion tool.