Challenge 2: Compiling the Same malloc Code as C vs. C++ — Possible Solution ==================================================================== test.c / test.cpp (identical contents): #include int main() { int *nums = malloc(5 * sizeof(int)); return 0; } Compiled as C: $ gcc test.c -o test_c (compiles successfully, no error or warning) Compiled as C++ (same file, renamed .cpp, or forced with -x c++): $ g++ -x c++ test.c -o test_cpp test.c: In function 'int main()': test.c:4:16: error: invalid conversion from 'void*' to 'int*' [-fpermissive] 4 | int *nums = malloc(5 * sizeof(int)); | ^~~~~~~~~~~~~~~~~~~~~~~~ | | | void* Report: the exact same source code compiles cleanly as C but fails to compile as C++, producing a genuine compile error rather than a warning -- exactly the chapter's own claim that this specific pattern is "valid C, invalid C++." The fix, matching the chapter's own corrected example, is adding an explicit cast: int *nums = (int *)malloc(5 * sizeof(int));, after which it compiles under g++ as well. WHY THIS WORKS AS AN ANSWER ------------------------------ This uses the IDENTICAL source file compiled under both compilers, showing the C compile succeeding and the C++ compile failing with a real, specific error message (not just a vague "it breaks"), directly confirming the chapter's own claim rather than restating it.