ProgrammingModerate
A struct P ps[] holds records, and an array of pointers pp[] is sorted with qsort. What happens to the records in ps?
- A. They are sorted, because the pointers point into ps
- B. They are reversed, because qsort reverses pointers
- C. They stay where they are, because only the pointers in pp move
- D. They are copied into pp and then deleted
Correct answer: C. They stay where they are, because only the pointers in pp move
Sorting pointers only permutes the pointers. The records keep their memory locations, so ps is unchanged.
More C Programming questions
- Which argument is correct as the size parameter in qsort for an array struct P recs[] of n records?
- A comparator for qsort is written as int cmp(const void a, const void b) { return ((const struct P )a)->k > ((const struct P )b)->k; }…
- For a struct array sorted by an int key, which bsearch call is correct to find a record with key k?
- A bsearch on a struct array returns NULL for a key that is actually present. Which is the most likely cause?
- A struct {int a; char b;} is used in an array of 3 elements on a platform with 4-byte int and natural alignment. What is sizeof(arr)?
- Using natural alignment, what is sizeof(struct { char c; short s; })?