Tuesday, September 21, 2010

Understanding the .C and .CPP File Extensions

The programs in Part One of this book are, of course, valid C++ programs and can be
compiled using any modern C++ compiler. They are also valid C programs and can be
compiled using a C compiler. Thus, if you are called upon to write C programs, the
ones shown in Part One qualify as examples. Traditionally, C programs use the file
extension .C, and C++ programs use the extension .CPP. A C++ compiler uses the file
extension to determine what type of program it is compiling. This is important because
the compiler assumes that any program using the .C extension is a C program and that
any file using .CPP is a C++ program. Unless explicitly noted otherwise, you may use
either extension for the programs in Part One. However, the programs in the rest of
this book will require .CPP.
One last point: Although C is a subset of C++, there are a few minor differences
between the two languages, and in a few cases, you may need to compile a C program
as a C program (using the .C extension). Any instances of this will be noted.

No comments:

Post a Comment