| Lesson 4 | Similarities in C and C++ program structure |
| Objective | Examine similarities between C/C++ program structure. |
|
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. It is not practical to implement OOP in C C++ supports multiple programming paradigms and multiple inheritance. 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). Of course, you can assume that any C++ feature relating to classes does not exist in C, including concepts like friends and 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. |
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.
- 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.
- 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 #.
- 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.