I am trying to figure out how to print the address of a function. Here is what I came up with
#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;
}
This is o / p something like this without any warnings and errors
address of function is =0x4006fa
address of function pointer is =0x7fffae4f73d8
The question is, is using the % p format specifier the right way to print the address of a function, or is there another way to do this?
user4418808
source
share