I have two questions
1.I saw that
int (*Ptr)(int,int);
Ptr=someOtherFuncion;
Its not should be like that?
Ptr=&som
The name of a function decays almost immediately to a pointer to the function, so someOtherFunction
decays to the same pointer that &someOtherFunction
gives you explicitly. In fact, the operand of the address-of operator (&
) is one of the few places were the decay doesn't happen.
This has amusing consequences: Even if you dereference the function pointer, it decays again right away. So the following are all equivalent:
someOtherFunction(1, 2);
(*someOtherFunction)(1, 2);
(**someOtherFunction)(1, 2);
(***someOtherFunction)(1, 2);
So, if you feel unwell assigning to a function pointer without an explicit address-of, by all means put the &
in there, but you don't have to.
To address the second part of the question: A function is always called through a function pointer, but because of the above-mentioned instant decay, normal functions can be called just the same way as function pointers.