Do function pointers need an ampersand [duplicate]

蓝咒 提交于 2019-11-27 21:49:06

No, there is no difference, since function can be implicitly converted to pointer to function. Relevant quote from standard (N3376 4.3/1).

An lvalue of function type T can be converted to a prvalue of type “pointer to T.” The result is a pointer to the function.

Is there a difference between these two calls:

No, there is no difference.

Maarten

bar(foo); is called the "short" version

bar(&foo); is how it is officially done

Functionally, there is no difference, however the second options is considered "good practice" by most since that way it is more obvious that foo is actually a function pointer and not an actual function.

This is similar as with arrays. If you have:

int foobar[10]; 

then foobar is an int *, but you can also do &foobar for the same result.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!