C++ & References
Alright, big moment — this week you're making the jump from C to C++. And don't worry, it's not like learning a whole new language from scratch. Think of it like this: C is like driving a manual car, and C++ is like upgrading to an automatic with cruise control. Everything you already know still works, but now you've got extra features that make your life a lot easier and your code a lot safer.
We're covering two major things. First, C++ I/O with cout and cin — the new way to print output and read input. Remember printf and scanf with all those format specifiers like %d, %f, %s? Yeah, you can forget about those. C++ figures out the type automatically. Way less room for mistakes. Second, you'll learn about references — basically a way to create another name for an existing variable. But why would you want that? Because references are the key to pass-by-reference, which lets functions modify the caller's variables directly instead of just working with a copy.
| C Style | C++ Style | What Changed |
|---|---|---|
printf("%d", x); | cout << x; | No format specifiers needed |
scanf("%d", &x); | cin >> x; | No & needed for basic types |
Pass by pointer (int* p) | Pass by reference (int& r) | Cleaner syntax, same effect |
By the end of this week, you'll be writing C++ programs with modern I/O and you'll understand why references are one of the most important things C++ brings to the table.