ProgrammingHard
Which statement about calloc(n, size) is guaranteed by the C standard?
- A. The n x size bytes are set to zero, which malloc does not do
- B. It returns a block that is uninitialised but zero-sized
- C. It can be used with free only if n is 1
- D. It zeroes memory only for types that have pointers
Correct answer: A. The n x size bytes are set to zero, which malloc does not do
calloc zero-fills its block and reports overflow of the product by returning NULL. Its arguments are not otherwise limited.
More C Programming questions
- A program calls free(p) and then reads p->v in the next line. What is the correct description?
- A hash chain delete on a singly linked bucket list is written with a pointer-to-pointer. Which description is the advantage?
- Building a list from n values by inserting each new node at the head is O(1) per insert. What is the order of the values when read from…
- Which C statement is correct for a node with an int field v and a next pointer, allocated and initialised to v = 7 with no next node?
- A doubly linked list stores prev pointers. How many pointer fields must change to insert a new node between two adjacent nodes A and B?
- A singly linked list of N = 10^6 nodes must answer 10^6 queries for the value at position k. Which approach is correct and fast enough?