ProgrammingHard
Records (name, score, age) are sorted by score descending, and by age ascending for equal scores. Input: (A,90,30), (B,90,25), (C,85,20). What is the output order?
- A. A, B, C
- B. B, A, C
- C. C, B, A
- D. B, C, A
Correct answer: B. B, A, C
B and A share score 90, so the younger B (age 25) comes first. C has the lowest score and comes last.
More C Programming questions
- qsort is used on an array of records where several records have equal keys. Which statement is guaranteed by the C standard?
- A sorted array of struct items is searched with bsearch for a key that is not in the array. What does bsearch return?
- An array struct P ps[] of pointers to records is to be sorted by an int field k with qsort. Which comparator is correct?
- For struct R { char c; short s; int i; } with natural alignment (char 1, short 2, int 4), what is sizeof(struct R)?
- Assume natural alignment with 4-byte int. What is sizeof(struct R[5]) where struct R is the eight-byte type from the previous record?
- struct Q { char name[6]; double score; char tag; }; with 8-byte double and natural alignment. What is sizeof(struct Q)?