I was asked in an interview to find out the address of the function without using any pointer or &. I could not answer his question, but when I checked it for an answer, he gave the following example in which the function f1 () calls the function f2 (). Thus, when calling the function f2 (), the stack stores the return address, which is nothing more than the address of the function f1 (). In the function f2 (), we can read the stack, and then find out the address stored on the stack, which has the function f1 (). Can someone explain this in detail, how can we read the stack from f2 () and find out the address of f1 ().
int main()
{
f1();
return 0;
}
void f1()
{
f2();
}
source
share