Getting Started
c3-6 named this course directly: the next step once OOP is layered on top of everything the C track already covers. Most of what you already know still applies. This chapter is about the specific places it doesn't.
g++ and clang++
The same underlying toolchains as c1-1's gcc/clang, extended for C++. The situation around build tooling hasn't changed either — no official package manager or build system, exactly as before; make/CMake still fill that gap, and c2-5's own Makefile material transfers directly, unchanged.
What's Source-Compatible With C
A large majority of valid C code compiles as valid C++, unchanged: variables, control flow, functions, arrays, pointers, and plain structs all carry over. Everything the C track covered about manual memory, bounds checking, and pointer discipline still applies at the same level as before — none of that gets replaced, only added to.
What's Not Compatible
A concrete, common example: in C, malloc's void * return implicitly converts to any pointer type. In C++, it does not — an explicit cast is required.
This reflects a broader theme worth noting immediately: C++'s type checking is stricter than C's in several places, not looser.
iostream vs. stdio
cout/cin/cerr are C++'s own I/O streams — using << and >>, which are genuinely overloaded operators (Chapter 6 covers writing your own), not format-string parsing the way printf/scanf work. Both remain fully usable in C++ — <cstdio> still works — but iostream is the idiomatic choice.
The Compile-Then-Link Model, Unchanged
c1-1's compile-then-link model transfers completely unchanged — same two conceptual steps, same idea of object files and linking. The only visible difference is convention: C++ source files typically use a .cpp extension, and g++ replaces gcc.
The Smallest C++ Program
Compare directly against c1-1's own hello world — the shape is identical; only the I/O mechanism changed.
| Concept | C | C++ |
|---|---|---|
| Print a value | printf("%d\n", x) | std::cout << x << std::endl; |
| void* implicit conversion | allowed | requires an explicit cast |
| File extension convention | .c | .cpp |
| Compiler | gcc / clang | g++ / clang++ |
void *-to-typed-pointer implicit conversion difference is a genuine, common trap when porting C code to C++ or mixing the two — code that compiled cleanly as C can fail to compile once treated as C++, specifically because C++'s type checking is stricter here.
Coding Challenges
Write a hello-world program using iostream that prints two separate lines with two separate std::cout statements, compile it with g++, and run it.
📄 View solutionTake a small C program using malloc without an explicit cast on its return value, and compile it first as C (gcc), then attempt to compile the identical file as C++ (g++). Report what happens in each case.
📄 View solutionExplain why the malloc void* conversion difference is evidence that C++ is, in at least this respect, MORE strictly typed than C — not simply "different" — and why that's a genuinely counter-intuitive fact given C++ is usually introduced as C "with more features."
📄 View solutionChapter 1 Quick Reference
g++/clang++— same underlying toolchains as C's own compilers, extended- Most valid C compiles as valid C++ unchanged — the manual-control discipline carries forward
void *requires an explicit cast to a typed pointer in C++ — not implicit, unlike Ciostream'scout/cinuse overloaded<</>>, not format strings —stdiostill works too- The compile-then-link model and
c2-5's Makefile material transfer completely unchanged - Next chapter: variables, references, and a genuine bool primitive from day one