Discussion
What is the return type of malloc() or calloc()?
Answer: C
Correct answer: void *
Both allocators return void *, a pointer to untyped storage. The caller assigns it to a pointer of whatever type it needs, and in C that conversion is implicit.
The design is what lets a single pair of functions serve every type in the language. It also means the allocator has no idea what will be stored in the block - alignment is guaranteed to suit any type, but the size must be computed by the caller, which is why sizeof appears in almost every call.
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