-2

What is the type definition of a variable x in this code?

typedef int *f(int);
f *x;
ufo
  • 93
  • 1
  • 11

2 Answers2

4

f is an alias for a function type that takes int as an argument and returns an int*.

As such it isn't particularly useful.

(If you wanted f to be a pointer to a function that takes an int and returns an int, you'd have to write typedef int (*f)(int);)

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • Style nit-pick: the OP's style is actually quite useful for people who prefer a consistent style when they work with any kind of pointers. If you use the typedef from the OP, you can declare a function pointer variable as `f* ptr;`. Rather than hiding the pointer behind typedef as in your case, and ending up with the more mysterious declaration `f ptr;`. – Lundin Oct 05 '16 at 09:51
1
typedef int* f(int);

type f is function with int parameters and returning pointer to int.

You cannot define a function using a typedef for a function type. please see the stack overflow answer.

Community
  • 1
  • 1
msc
  • 33,420
  • 29
  • 119
  • 214