answersLogoWhite

0


Best Answer

The declaration int (*f) (int*); declares a function pointer named f. The function pointer can be assigned the address of any function that accepts a pointer to int and returns an int. Function pointers can be used to pass functions to functions. Normally we use typedefs to simplify the notation of function pointers:

typedef int (*f) (int*);

int x (int*);

int y (int*);

f fp; // declare a function pointer of type f

int z = 42;

fp = x; // point to the x function

fp (&z); // invoke function via pointer

fp = y; // point to the y function

fp (&z); // invoke function via pointer.

A typical usage of function pointers is to provide a predicate for a comparison sort algorithm. This makes it possible for the same sorting algorithm to compare objects using different predicates. For example:

typedef bool (*pred) (int, int); // function pointer type named pred

void sort (int a[], size_t len, pred func) {

// simple shell sort

for(int i=len/2; i>0; i=i/2)

{

for(int j=i; j<len; j++)

{

for(k=j-i; k>=0; k=k-i)

{

if( !func (a[k+i], a[k]) // invoke the predicate function

{

swap (a[k], a[k+i]);

}

}

}

}

}

// Declare predicates...

bool less_than (int a, int b) { return a<b);

bool greater_than (int a, int b) { return a>b; }

int main () {

int x[] = {3,5,2,4,1};

sort (x, 5, less_than); // sort array of 5 elements in ascending order

sort (x, 5, greater_than); // sort array of 5 elements in descending order

return 0;

}

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does the C statement int open parenthesis asterisk f close parenthesis open parenthesis int asterisk close parenthesis declare?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

The break statement is required in the default case of a switch selection structure?

Ends the case statement. Without it, any code after where the break; is supposed to be will get executed as well until it does encounter a break; or the end of the switch.Code Example:char cTest = 'a';switch(cTest) {case 'a':/* Code here gets executed. */case 'b': //* Code here gets executed. */case 'c':/* Code here gets executed. */break;case 'd':/* Code here won't be executed. */default:/* Code here won't be executed. */}


Algorithm for infix to prefix conversion?

Algorithm to Convert Infix to Prefix FormSuppose A is an arithmetic expression written in infix form. The algorithm finds equivalent prefix expression B.Step 1. Push ")" onto STACK, and add "(" to end of the AStep 2. Scan A from right to left and repeat step 3 to 6 for each element of A until the STACK is emptyStep 3. If an operand is encountered add it to BStep 4. If a right parenthesis is encountered push it onto STACKStep 5. If an operator is encountered then:a. Repeatedly pop from STACK and add to B each operator (on the top of STACK) which has same or higher precedence than the operator.b. Add operator to STACKStep 6. If left parenthesis is encontered thena. Repeatedly pop from the STACK and add to B (each operator on top of stack until a left parenthesis is encounterd)b. Remove the left parenthesisStep 7. Exit


Does the Sagamore bridge close in high wind?

sagamore bridge is close yes o no


What is close system in System analysis?

close system are the type of system that do not interact with the environment


Which way to turn valve knob to close?

On a round valve handle you normally turn it clockwise to close .

Related questions

How do you simplify open parenthesis x squared y close parenthesis times open parenthesis y z close parenthesis times open parenthesis x y z close parenthesis?

x cubed y cubed z squared


What is the use of open and close parenthesis?

open parenthesis


How to use open and close parenthesis?

Open parenthesis are used at the beginning of a quote. Close parenthesis are used at the end of a quote after the punctuation.


How do you make a bunny on Microsoft Word?

(\_/)(^_^)(") (")This bunny looks best in Geneva on Microsoft word.DIRECTIONS1. open parenthesis (shift+9) + backward slash + underscore (shift + dash) + forward slash + close parenthesis (shift+0)2. open parenthesis + carat (shift+6)+underscore+carat+close parenthesis3. open parenthesis + quotes (shift + apostrophe) + space + quotes + close parenthesis--or--(\(\('.')(( )( )This bunny looks best in Times New Roman on Microsoft Word.DIRECTIONS:1. open parenthesis (shift+9)+backward slash + open parenthesis + backward slash2a. open parenthesis + open quote + space + open quote + close parenthesis2b. go back to step 2a. and change the space to a period.3. open parenthesis + open parenthesis + space + close parenthesis + open parenthesis + space + close parenthesis


What is open parenthesis xplus2 close parenthesis open parenthesis xminus1 close parenthesis less than or equal to 0 in interval notation?

the answer is either 42 36 58 12 5 6 90 45 18


How do you simplify open parenthesis x squared times y squared close parenthesis to the cube plus open parenthesis x cubed times y cubed close parenthesis to the second power?

(x2y2)3 + (x3y3)2 = 2x6y6.


What is half a parenthesis called?

parenthesis = singular form, i.e., ( OR ) parentheses = plural form, i.e., ( AND ) The singular forms are generally referred to as: open or left parenthesis = ( close or right parenthesis = ) As for the top or bottom half of one parenthesis? I have no idea.


What are the names of the keyboard symbol?

well, there is a number symbol, money symbol, percent symbol, and symbol, star symbol and these are just some of them...


What does a semicolon and close parenthesis mean?

A semicolon followed by a closing parenthesis, &quot;;)&quot;, is often used in written text as a representation of a winking face emoticon. It is typically used to convey a playful or sarcastic tone in digital communication.


What is six times one open close parenthesis times five give the answer?

30


What is the answer to 5 open parenthesis a plus 2 close parenthesis?

the equation is 5(a+2) if a is 1 than the answer is 15 if a is 2 than the answer is 20 if a is 3 than the answer is 25 etc...


Open parenthesis 16 times 2 square close parenthesis raised to the second power?

(16 x 22)2 = (16 x 4)2 = (64)2 = 4096. Always perform the operations inside parenthesis first.