Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What does the malloc() function return if it fails to allocate memory?

  1. NULL

  2. 0x0

  3. An error code

  4. Both A and B are correct

The correct answer is: Both A and B are correct

If the malloc() function fails to allocate memory, it will return a NULL pointer or a memory address of 0x0, depending on the system. Therefore, both options A and B are correct. Option C is incorrect because the malloc() function does not return an error code when it fails. Instead, it returns NULL or 0x0, indicating a failure to allocate memory.