Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function allocation

Tags:

c++

function

Where are functions stored in a C++ program?

For example

int abc()
{
   //where am I stored? 
}

I know that we can take the address of a function, that means functions are stored somewhere in memory. But I have already read at many places that no memory allocation for functions takes place.

I am confused. My question may seem vague to many of you but I can't help.

like image 260
Prasoon Saurav Avatar asked Jul 28 '26 18:07

Prasoon Saurav


1 Answers

Before being run, your program is loaded into memory, and that includes loading the code that implements the functions.

Once the program starts to run, no memory allocation for functions takes place; it's done before the program starts, by the system's program loader.

This assumes a "normal" desktop OS, for embedded systems running code out of ROM, the situation is often different.

like image 110
unwind Avatar answered Jul 30 '26 09:07

unwind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!