Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is just a general question for an interview that I\'m studying for. I was h

ID: 3551665 • Letter: T

Question

This is just a general question for an interview that I'm studying for. I was hoping someone can explain on a high level as to how this happens. I'm not expecting a long answer, just something accurate for my understanding!


What i know:
I remember in one of the C and assembly courses I took, how we worked wtih drawing stack frames for stacks and heaps, with ints, chars, halfs, pointers, and etc within those stack frames. Does it have anythign to do with this? Or is it more related to using malloc, realloc, calloc, and free?

Thank you!

Explanation / Answer

When a program begins executing in the function main(), space is allocated on the stack for all variables declared within main().

If main() calls a function, func1(), additional storage is allocated for the variables in func1() at the top of the stack. The parameters passed by main() to func1() are also stored on the stack.


The heap segment provides more stable storage of data for a program; memory allocated in the heap remains in existence for the duration of a program. Therefore, global variables (storage class external), and static variables are allocated on the heap.

To allocate memory on the heap, you must use malloc() or calloc(), which are built-in C functions.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote