Distinguishing C from C++
Plain C is a simple, low-level language, and it's nearly a subset of C++, which was originally named "C with classes". If you look at the size of the author's book on each language, you can immediately see the big complexity difference!
Generally, these features are shared between C and C++:
- Variables like "int" and "char"
- Arithmetic operations like + - * /
- Assignments like =, or += and such.
- Functions, curly braces {}
- if statements, switch statements
- for loops, while loops, do loops
- arrays
- pointers
These features are only C++, not available in plain C:
- Object oriented features like class and virtual methods. Plain C uses functions or structs for similar operations.
- new and delete. Plain C uses functions named malloc and free instead.
- templates. Plain C uses macros for similar features.
- std::string. Plain C uses arrays of characters for strings, which are more error-prone.
- std::cout and std::cin. Plain C uses printf and scanf, which I actually prefer, but are harder to learn, and can't be extended.
- std::vector. Plain C uses bare arrays, and a function named realloc.
- std:: anything else!
In this class, we'll be covering both the implementation of C++ features in plain C and assembly, and plain C as a language on its own. Quite a few large projects are built in plain C, including the linux kernel, and many system libraries.
CS 301 Lecture Note, 2014, Dr. Orion Lawlor, UAF Computer Science Department.