4 c pointers function-pointers function
我一直试图弄清楚如何打印函数的地址,这就是我想出来的
#include<stdio.h>
int test(int a, int b)
{
return a+b;
}
int main(void)
{
int (*ptr)(int,int);
ptr=&test;
printf("The address of the function is =%p\n",ptr);
printf("The address of the function pointer is =%p\n",&ptr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它没有任何警告和错误
address of function is =0x4006fa
address of function pointer is =0x7fffae4f73d8
Run Code Online (Sandbox Code Playgroud)
我的问题是否使用%p格式说明符是打印函数地址的正确方法还是有其他方法可以这样做?