C++ shares most of its basic syntax with C, but it adds classes, references, function overloading, templates, namespaces, exceptions and a large standard library. C has structs without member functions, no overloading and manual memory management, while C++ supports object-oriented, generic and functional styles and manages resources with RAII.
This article focuses on syntax and feature differences, with side-by-side code, and notes the modern C++20 and C23 versions.
In C a struct only holds data, and operations are separate functions that take a pointer to it.
In C++ a struct can also have member functions, constructors and access control. The only difference from class is that members are public by default.
C requires a unique name per function. C++ lets you reuse a name with different parameter types and supply default arguments.
C passes by value and uses pointers to modify arguments. C++ adds references, which are aliases that cannot be null or reseated.
C++ templates generate type-safe code at compile time. C uses macros or void *, which lose type checking.
max_of(3, 7) and max_of(2.5, 1.5) both work, and C++20 concepts such as std::totally_ordered produce clear errors when a type does not qualify.
C uses malloc and free. C++ has new and delete, but modern code prefers containers and smart pointers (std::unique_ptr, std::shared_ptr) so cleanup happens when the owner goes out of scope.
try, catch and throw. C relies on return values and errno.namespace, avoiding collisions. C has one global namespace for functions and file scope for static ones.printf and scanf. C++ uses streams (std::cout, std::cin) and, from C++20, std::format.char arrays ending in '\0'. C++ provides std::string and std::string_view.C++ is stricter about types. In C you can assign a void * to any pointer type without a cast, which C++ rejects, and a C-style cast (int)x can silently do the wrong thing. C++ splits casts by purpose: static_cast for well-defined conversions, dynamic_cast for checked downcasts, const_cast to remove const, and reinterpret_cast for low-level reinterpretation.
| Topic | C | C++ |
|---|---|---|
| Source files | .c | .cpp, .cc, .cxx |
| Standard headers | <stdio.h> | <iostream>, <vector>, <string> |
| Boolean | bool (C23, <stdbool.h> before) | bool |
| Casts | (int)x | static_cast<int>(x) |
| Null pointer | NULL or nullptr (C23) | nullptr |
| Inheritance and virtual functions | No | Yes |
| Compile-time evaluation | Limited, constexpr in C23 for objects | constexpr and consteval functions |
Not exactly. Most C code compiles as C++, but features such as implicit conversion from void *, variable-length arrays and some designated initializer forms are not valid C++.
Yes. Declare C functions inside extern "C" { } in the C++ code so the linker uses C naming.
static_cast and similar casts?They make the intent of a conversion explicit and searchable, and the compiler rejects unsafe ones that a C-style cast would allow.
C++20 or C++23 for C++, and C17 or C23 for C, depending on your compiler support.
C++ extends C with classes, overloading, references, templates, exceptions, namespaces and RAII, while C stays small and procedural. Use C where simplicity and minimal runtime matter, and C++ for projects that benefit from stronger abstractions.