Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone explain what is *cmp? And how the function double_ascending is used? 10.4 PAGE 180 PROGRAMMING, PROBLEM SOLVING, AND ABSTRACTION parentheses necessary. Instead, C

Can someone explain what is *cmp? And how the function double_ascending is used? image text in transcribed
image text in transcribed
10.4 PAGE 180 PROGRAMMING, PROBLEM SOLVING, AND ABSTRACTION parentheses necessary. Instead, C allows the obvious abbreviation, and F (apannt and list) has exactly the same effect. An analogy to bear in mind when digesting Figure 10.9 is that of arrays array pointers. An array is a pointer constant, in the same way that sin is a function constant. Just as a pointer variable can be assigned the base address of an array and then used to access the elements in the array, so too a function pointer can be assigned the aps be rather un- the value of a function, and thereafter used to call the function. If that were all there was to function pointers, they would perhaps be rather un- interesting. But they can also be passed as arguments into other functions, and this is where it starts to become fun. Figures 10.10 and 10.11 give a more compelling ex- ample that shows the tremendous flexibility that is achieved with function pointers. In Figure 10.10, functions double ascending and string.descending are defined. They seem to operate on different types, but the use of void. arguments means that in fact they have the same type-both are int (voids, void), functions that take two void arguments and return an int value. int is.sorted (void A, sizet nelem, size t size, int (+cmp) (void.,vgid.)) int double ascending (void v1, void v2) double di-vl d2-2; if (.dl>*d2 return 0 return m int string descending (void vi, void v2) char ..sl-vl, .s2-v2: return -stremp(.s1, s2) int main(int arge, char 11.87, 3.43, 7.64, 7.68, 8.16, 9.86) argv []) { double X(I char st1 "wombat", "vallaby*, "quo11", "quokka", koala", "kangaroo" "goanna", "bilby") i if (issorted (X, sizeof (X)/sizeof ( x), sizeofX) double ascending)) ( printf("Array X is ascendingln") if (is_sorted(s, sizeof (S)/sizeof ( s), sizeof ( s), string.descending)) f printf ("Array S is descendingln") return 0 Figure 10.10: Passing arguments to a polymorphic function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions