Programming C++  «Prev  Next»
Lesson 4Similarities in C and C++ program structure
ObjectiveExamine similarities between C/C++ program Structure.

Similarities between C and C++ Programs

C++ supports Object-oriented programming and C does not

One of the most commonly known differences between the two programming languages is that C++ supports OOP and C does not. C was originally built to be a procedural programming language and it is not practical to implement (OOP) object-oriented programming in C.
C++ supports multiple programming paradigms and multiple inheritance and OOP is one of the programming paradigms. For example, C++'s parameterized templates allow for generic programming.
C++ has a few characteristics of functional programming (in the form of function pointers). Furthermore, you can assume that any C++ feature relating to classes does not exist in C, including concepts like
  1. friends and
  2. virtual functions.
One can summarize the differences between the languages through the following statement:

C++ has better support for multiple programming paradigms when compared to C.

C++ is a superset of C and any C++ feature relating to classes does not exist in C.

C/C++ Compatibility

With minor exceptions, C++ is a superset of C and most differences stem from the fact that C++ has greater emphasis on type checking.
Well-written C programs tend to be C++ programs as well and a compiler can diagnose every difference between C++ and C. Most C code is Classic C or C99.

C and C++ Are Siblings

Classic C has two main descendants:
  1. ISO C and
  2. ISO C++.
Over the years, these languages have evolved at different paces and in different directions. One result of this is that each language provides support for traditional C-style programming in slightly different ways. The resulting incompatibilities can make life challenging for people who use both C and C++:
  1. For people who write in one language using libraries implemented in the other,
  2. and for implementers of libraries and tools for C and C++.

As you have seen in the last several lessons, the organization of a C++ program is very similar to the organization of a C program.
  1. C++ relies on an external standard library to provide input/output. The information the program needs to use this library resides in the library file iostream.h.
  2. C++ uses a preprocessor to handle a set of directives, such as the include directive, to convert the program from its preprocessing form to pure C++ syntax. These directives are introduced by the symbol #.
  3. The function main() is used as the starting point for execution of the program. It obeys the C++ rules for function declaration. The function main() implicitly returns zero, indicating normal termination. Other return values would indicate an error condition.