C或C++函式的地址


在C或C++中,變數儲存在記憶體中,因此我們可以獲取它們的記憶體地址。同樣,函式也儲存在記憶體中,因此它們也有一些地址。為了得到地址,我們可以僅使用函式名,而不用括號。

請檢查以下程式以獲得明確的概念。

示例

#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);
}

輸出

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

更新於:2019年07月30日

3K+瀏覽量

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.