There is this code:
void a() { }
int main(){
a();
(****&a)();
return 0;
}
How does it happen that statement (****&a)();
has the same effect as a();
?
There is this code:
void a() { }
int main(){
a();
(****&a)();
return 0;
}
How does it happen that statement (****&a)();
has the same effect as a();
?
It's all because of function-to-pointer conversion (§4.3):
An lvalue of function type
T
can be converted to a prvalue of type “pointer toT
.” The result is a pointer to the function.
&a
first gives you a pointer to a
. Then you dereference it with *
giving you the function itself. You then attempt to dereference that function, but since you can't, it undergoes function-to-pointer conversion to get the pointer again. You dereference that pointer with *
, and so on.
In the end (****&a)
denotes the function a
and you call it, since you can apply ()
to a function without it undergoing function-to-pointer conversion.