Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

ที่อยู่ของฟังก์ชันใน C/C++

ฟังก์ชันเก็บอยู่ในหน่วยความจำเช่นเดียวกับตัวแปร สามารถดึงที่อยู่ได้โดยใช้ชื่อฟังก์ชันโดยไม่ใส่วงเล็บ

ตัวอย่าง

#include <stdio.h>

void my_function() {
    printf("Hello World");
}

int main() {
    printf("The address of my_function is: %p\n", my_function);
    printf("The address of main is: %p\n", main);
    return 0;
}

ผลลัพธ์

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