ProgrammingModerate
A dynamic array starts with capacity 1 and doubles whenever it is full, until its capacity is at least 10. What is the final capacity?
- A. 10
- B. 12
- C. 8
- D. 16
Correct answer: D. 16
The capacities run 1, 2, 4, 8, 16. The first value that reaches 10 or more is 16, after four reallocations.
More C Programming questions
- A complete binary tree has levels 0 to 2 (depth 3 in this count). How many nodes does it have?
- A chained hash bucket holds the nodes 30, 20, 10 in that order from the head. The node holding 20 is deleted and freed. How many nodes…
- A program makes three malloc calls and two free calls, with no other allocations. How many blocks are still allocated when the program…
- int a = calloc(4, sizeof a); int sum = 0; for (int i = 0; i < 4; i++) sum += a[i]; printf("%d", sum); What is printed?
- Which statement about calling free on a null pointer is correct in C?
- A pointer p is freed with free(p) and then set to NULL. Why is this safer than leaving it dangling?