Home >Backend Development >C++ >Address of function in C or C++

Address of function in C or C++

WBOY
WBOYforward
2023-08-27 19:05:02833browse

C 或 C++ 中函数的地址

In C or C, variables are stored in memory, so we can get their memory addresses. Likewise, functions are stored in memory, so they also have some address. To get the address we can just use the function name without the brackets.

Please check the following procedure to get a 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

The above is the detailed content of Address of function in C or C++. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete