Discussion
malloc() returns a NULL if it fails to allocate the requested memory.
Answer: A
Correct answer: TRUE
When malloc cannot satisfy a request it returns a null pointer. That is the only way it reports failure - there is no error code and nothing is set beyond, on most systems, errno.
Checking the return value is therefore the caller's responsibility, and omitting the check is a common fault: the program proceeds to dereference a null pointer and crashes at a line some distance from the real cause. Note that malloc(0) may legitimately return either null or a unique pointer.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development