Machine-translated by Google. Questions are authored in English.
Top

Discussion

Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ]

  • A.Yes, and we can use the function value conveniently
  • B.Yes, but we call the function again to get the value, not as convenient as in using variable
  • C.No, C does not support it.
  • D.This case is compiler dependent

Answer: C

Correct answer: Yes, but we call the function again to get the value, not as convenient as in using variable

C does allow it: a parameter written as a function is adjusted to a pointer to that function, so void wow(int func()) means void wow(int (*func)()). But what is passed is the function itself, not a value - so inside wow you must call it to obtain anything, which is less convenient than passing the value. This is the mechanism behind callbacks, such as the comparison function given to qsort.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.