Open In App

C Quiz – 107 | Question 5

Like Article
Like
Save
Share
Report

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

C




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


(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
Please comment below if you find anything wrong in the above post


Last Updated : 28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads