Friday, November 8, 2013

Same Program, But Different Output on C and C++

The C++ language began as enhancements to C, first adding classes, then virtual functions, operator overloading, multiple inheritance, templates and exception handling, among other features.

We all know that C++ is often considered to be a superset of C, but this is not strictly true. Most C code can easily be made to compile correctly in C++, but there are a few differences that cause some valid C code to be invalid or behave differently in C++.

Here are some examples of the programs, save them with extention '.c' and '.cpp', and compile & run.