C Programming - Complicated Declarations - Discussion

8. 

Declare the following statement?
"A pointer to a function which receives nothing and returns nothing".

[A].
void *(ptr)*int;
[B].
void *(*ptr)()
[C].
void *(*ptr)(*)
[D].
void (*ptr)()

Answer: Option D

Explanation:

No answer description available for this question.

Saran said: (Sep 13, 2011)  
Simple trick is that there is only one pointer is mentioned and pointer is represented by *. So the answer is void(*ptr)().

Manas said: (Dec 4, 2011)  
@Saran you are great.

Patrick said: (Jun 24, 2013)  
Is there any difference between void *ptr() and void (*ptr)()?

Yug Verma said: (Jul 24, 2013)  
Yes, *ptr()-> ptr is a pointer function which returns void and void (*ptr)() -> ptr is a pointer to a function which returns void.

Siddu said: (Nov 3, 2014)  
"void *(*ptr)(*)" What does it mean?

Kiran Bhosale said: (Feb 29, 2016)  
This declaration is wrong and will give the compilation error "expected declaration specifiers or \'. \' before \'*\' token", i.e. there is no data type before * in (*).

If we replace this expression with something like this "void * (*ptr) (int *)", then it would be pointer to function that "returns void pointer and accepts integer pointer as an argument".

Vinay said: (Aug 15, 2016)  
@Saran

You are the great man your trick working everywhere. Thank you very much.

Rani said: (Jun 6, 2018)  
Please tell me the difference between pointer to function and pointer function.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.