Pointers to Functions Flashcards

1
Q

Use the following functions:

char func1(char c);

char * func2(char *s);

  1. How do you delcare a function pointer?
  2. How do you assign addresses to the funtion pointers?
  3. How do you invoke the functions using the pointers?
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you use typedef with a function pointer?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What would you put into the blank box to pass a function pointer into integrate?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when a function name isn’t followed by paraentheses when passed as a parameter into a function?

for example:

result = integrate(sin, 0.0, PI/2);

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you call a function with a pointer in the body of another function.

Example: function pointer is f which takes x as an argument.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In general, how does the standard library qsort function work? What does it need?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the prototype for qsort?

What do each of the parameters need/represent?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In the below example of inventory, how would we call qsort? What would qsort do with the array?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the code for compare_parts that can be used to sort the inventory array(3 versions)? What order is it sorted into?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the multi uses for function pointers?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the code for an array whose elements are function pointers?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the code for an example of a call of the function stored in position n of the file_cmd array?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly