Is there a way to find out the address of main() in C or C++ ? Since it is itself a function ,would there be an address of it own ?
Sure. Simply go ahead and do it.
#include
int main(void)
{
printf("%p\n", &main);
}
It is not permitted to take main
's address so, for your purposes, there isn't one:
[C++11: 3.6.1/3]:
The function main shall not be used within a program. [..]
However, in GCC you can take the same approach as you would in C, via a compiler extension:
#include
int main()
{
std::cout << (void*)&main << '\n';
}
You will receive a warning that this is not compliant.