ProgrammingHard
Using natural alignment, what is sizeof(struct { char c; short s; })?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: A. 4
c is at offset 0, a pad byte puts s at offset 2, and the struct size is 4.
More C Programming questions
- For struct { char name[4]; int v; } with a 4-byte int and natural alignment, what is sizeof of the struct?
- A selection sort on 5 elements (find the minimum, swap into place) makes how many key comparisons in total, for any input?
- Bubble sort with an early exit when a pass makes no swap is given an already sorted array of 5 elements. How many comparisons does it make?
- A sorted array of 10^6 keys answers 10^5 queries of the form 'how many keys lie in [L, R]'. Which approach is correct and fast enough?
- In a sorted array with duplicates, which index does a lowerbound search return for the key 5 in [1, 5, 5, 5, 8]?
- Two sorted struct arrays of sizes n and m are merged into a new array. How many elements does the merged array hold?