What section of memory is used to make stack?

1 answer

Answer

1059356

2026-03-23 13:45

+ Follow

Stack memory is memory assigned to a task or other instruction loop that it uses to perform instructions. Stack is used any time variables are declared inline with the code (see example below). Stack is also used for preserving registers whenever the processor switches contexts (from task to interrupt, between interrupts, or between tasks).

Stack is provide either by the Operating System when the task is started, statically when a task is defined (as would be in an RTOS), or at compile time if there is no operating system. In the third case, the stacks in the system are assigned for each of the various interrupt contexts and the main loop.

Stack usage example:

void somefunc(int a)

{

// "int a" will be in a CPU register

int i=0; // May be either a CPU register or on the stack, depending on CPU architecture and compiler.

char c[10]; // Will exist on the stack

struct somestruct *ss=malloc(sizeof(struct somestruct));

// The memory that ss points to will be in the "heap", the pointer to this memory will be on the stack.

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.