Conclusion
You have covered a lot of ground — from printf format specifiers to file descriptors to pointer ownership. Here are the key takeaways:
- C and C++ are different languages. Modern C++ has evolved far from C. Knowing one does not mean you automatically know the other.
printfandscanfreplaceiostream. Format specifiers must match argument types.scanfneeds&for scalar variables.- C types are explicit. No
auto, nostd::string, no classes. You have basic types,typedef, arrays, andstruct. - C shares most operators with C++ but there is no operator overloading,
<<and>>are strictly bitwise, and boolean results are plainint. - Control flow is nearly identical to C++ except there are no range-based
forloops andgotois an accepted idiom for cleanup. - Pointers hold memory addresses. Use
&to get an address,*to follow one, and->to access struct fields through a pointer. Arrays decay to pointers, and pointer arithmetic moves in units of the pointed-to type. - All function arguments are pass by value. To modify a caller’s variable, pass a pointer to it. Use
constparameters to document read-only intent. - Know where your memory lives. Global variables last the whole program, local variables live on the stack, and dynamic memory from
malloclives on the heap until youfreeit. - Strings in C are
chararrays terminated by'\0'. You must manage buffer sizes manually and use functions likestrlen,strcpy,strcmp, andstrcatinstead ofstd::stringmethods. stdioprovides buffered I/O throughFILE *pointers. Low-level I/O uses file descriptors and system calls likeread,write, andopen.- C has no exceptions. Use return codes for errors and
gotocleanup to release resources in reverse order. - Function pointers replace lambdas.
qsortis the classic example — pass a comparison function to sort any type. exitterminates from anywhere. Use it for fatal errors, and register cleanup that must always run withatexit.extern "C"bridges C and C++. It turns off name mangling so the C++ linker can find C functions.- Always know who owns a pointer. The owner — and only the owner — calls
free.
Es un mundo nuevo, but you have the C++ foundation to build on. The syntax will feel familiar even when the idioms are different. Write small programs, compile them with cc, and get comfortable with the compiler’s warnings — they are your best amigo.
Buena suerte — you’ve got this.
Content outline and editorial support from Ben. Words by Claude, the Opus.