ProgrammingHard
In C, what is the value of a freshly malloc'd int that the program never initialises?
- A. Indeterminate, so reading it is undefined behaviour
- B. Zero, as with calloc
- C. The value of the previous allocation
- D. Always the bit pattern 0xCD
Correct answer: A. Indeterminate, so reading it is undefined behaviour
malloc leaves memory uninitialised. Reading an indeterminate value is undefined, and debug builds only pretend it has a pattern.
More C Programming questions
- A linked list is reversed with the recursive function rev(n): if (!n || !n->next) return n; h = rev(n->next); n->next->next = n; n->next =…
- A malloc'd array of 10 structs is later passed to free(&arr[3]). What is the correct description?
- Which declaration allocates a 3 x 4 int matrix as one contiguous block with a single free needed?
- A list of N nodes is freed with free() on each node but the next pointer is read after freeing it. Which order is correct?
- C(0) = 1 and C(n) = sum over i from 0 to n-1 of C(i) C(n-1-i). What is C(4)?
- A 3 x 3 grid holds 1 to 9 row by row, so row 0 is 1 2 3, row 1 is 4 5 6 and row 2 is 7 8 9. What is the sum of the 2 x 2 block with rows 1…