Reputation: 1236
Can anybody explain exactly what this type means int * (*) (int *)
in C language?
Thanks,
Upvotes: 0
Views: 1880
Reputation: 747
You have to read about "left-right" rule on reading C declrations. Here is the link provides instructions. Rather than giving anwser this will help you learn the stuff to practice on your own. http://cseweb.ucsd.edu/~ricko/rt_lt.rule.html
Upvotes: 1
Reputation: 180191
Unless int
is defined as a macro, int * (*) (int *)
contains neither any constants nor any identifiers, therefore it cannot be an expression. Rather, it is a type. Specifically, it is the type of a pointer to a function that accepts one parameter, of type int *
, and returns a value of type int *
. For example, it is compatible with a pointer to this function:
int *foo(int *x) {
return x + 1;
}
You might use it in a typecast expression, such as in this contrived example:
int *(*p)() = foo;
int *(*p2)(int *) = (int * (*)(int *)) p;
// here ------------^^^^^^^^^^^^^^^^^^
Upvotes: 3
Reputation: 11921
This
int * (*) (int *); /* not valid expression */
is not a valid syntax in C
. You might want to know
int * (*func) (int *); /* valid : function pointer declaration */
where func
is a function pointer, can point to a function which takes input argument of int*
type and which returns int*
.
Upvotes: 2