C Programming - Complicated Declarations - Discussion

9. 

What do the following declaration signify?

int *f();

[A]. f is a pointer variable of function type.
[B]. f is a function returning pointer to an int.
[C]. f is a function pointer.
[D]. f is a simple declaration of pointer variable.

Answer: Option B

Explanation:

No answer description available for this question.

Sathish said: (Aug 2, 2010)  
if we put *f in parenthesis it is pointer to function here parenthesis have greater precedence than astrek operator.

Prajakta said: (Mar 20, 2014)  
Trick: here () indicates function(method in java) and * sign is given before () so f is function returning pointer and return type is int so, answer B is correct.

Athul M Das said: (Sep 12, 2014)  
Int *f() is an int pointer but when enclosed in parenthesis int (*f)() it becomes a pointer to a function returning int.

Jarvis said: (Dec 1, 2014)  
OK its cool declaration but can you give an example program so that it'll be more clear?

Natwar said: (Jun 30, 2015)  
#include<stdio.h>

int *f(void)
{
int *x;
int a=10;
x = &a;
printf("*x = %d\n",*x);
return (*x);
}
int main()
{
int *b;
b = f();
printf("*b = %d\n",b);

return 0;
}

A.Srikanth said: (Dec 16, 2017)  
No, it is wrong @Natwar.

Please correct in return statement.t return(x) instead of return(*x) and in main() function printf statement printf("*b=%d\n",*b) instead of printf("*b=%d\ n",*b);.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.