C Quiz – 107 | Question 5

For the following declaration of a function in C, pick the best statement

filter_none

edit
close

play_arrow

link
brightness_4
code

int [] fun(void (*fptr)(int *));

chevron_right


(A) It will result in compile error.
(B) No compile error. fun is a function which takes a function pointer fptr as argument and return an array of int.
(C) No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. Also, fptr is a function pointer which takes int pointer as argument and returns void.
(D) No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. The array of int depends on the body of fun i.e. what size array is returned. Also, fptr is a function pointer which takes int pointer as argument and returns void.


Answer: (A)

Explanation: As per C standard, a function can’t have an explicit array as return type. That’s why the above would result in compile error. There’re indirect ways if we need an array as an output of a function call. For example, a pointer can be returned by function by return statement while providing the size of array via other means. Alternatively, function argument can be used for this.

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.