7.
float (*abc)(float x);
put in all the parentheses:
float ((*abc)(float x));
- abc is being declared (not x),
- it is a pointer to something:
- a function that takes a float and returns ...
- another float.
abc is not a function here. Abc is a normal variable, that can contain
a pointer to a function. The function it points to must be one that
takes a float argument and returns a float result, like the mathematical
function sine for example.
You could in fact use the variable for exactly that purpose, by
writing the assignment abc=sin;. Normally you would expect
to have to put an & in front of the name sin to produce
a pointer, but just like array names, function names are automatically
assumed represent pointers. Most compilers will whine bitterly if
you put the & in.
After such an assignment, you could say x=abc(y);, which would
have exactly the same effect as x=sin(y);, except that now you can
have a program that dynamically chooses which function to call.
NOTE You may think that I left something out in the last
paragraph. abc isn't a function, its a pointer to a function,
so we should say (*abc)(y) instead of abc(y).
Unfortunately, C doesn't look at it that way. The name of a function
always stands for the address of that function, just like with an array.
The name sin actually represents a pointer to the sine function; it
is as though an & had been automatically added. So when you say
sin(y) you are really putting a function pointer before the
opening parenthesis, not a real function at all. C wouldn't know how
to handle a real function if you gave it one. So, abc,
being declared as a function pointer is of the same status as sin;
no * is needed or even allowed.
Normal function names,
even though they are pointers, are still constants. You can't assign a new value
to sin. When you define a function like this:
void fff(char x)
{ printf("%c%c%c",x); }
it is as though you really defined a constant pointer-"variable" of the right
type, and somehow initialised it with the right address, like this:
void (* const f)(char) = correct memory address;
Yes, that is proper C. The const before the name f specifies that
f is a constant, which shouldn't surprise you. Apart from that it has the
exact same form as the declaration of a function-pointer variable, which is what it is.
abc is just a simple pointer, so its size is 4.