I’m preparing for my UNIX exam and there is a question about memory location of C variables.
Let’s say we have code like this
char sth;
int some_function(int arg) {
int some_int;
// some code here
}
so I suppose that sth is located on the heap, some_int on the stack, but where is arg located?
Can somebody please explain how are C variables managed?
Thank you
Note that everything of this is implementation dependent. The C standard does not even utter the words stack, heap and so on. It just talks about the behavior that is expected from variables depending on their storage(
static,extern,registeretc).Having said so usually
argwill be located in the stack frame which is provided for the function. It’s scope is limited to the function just as scope ofsome_int.By the way
sthis not on heap it has a static global storage.