Address of a function in C or C++


In C or C++, the variables are stored into memory, so we can get their memory addresses. Similarly, the functions also are stored into the memory, so they also have some addresses. To get the address we can use the function name only without using the parenthesis.

Please check the following program to get the clear idea.

Example

#include <stdio.h>
void my_function() {
   printf("Hello World");
}
int main() {
   printf("The address of the my_function is: %p\n", my_function);
   printf("The address of the main is: %p\n", main);
}

Output

The address of the my_function is: 0000000000401530
The address of the main is: 000000000040154B

Updated on: 30-Jul-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements