Determining variables stack or heap in C? -
let's have these variables , pointers. how determine in stack or heap?
#include <stdio.h> #define size 5 int main( void ) { int *zlkr; int *alkr= null; void *slkr= null; int num, k; int a[size] = { 1, 2, 3, 4, 5 }; zlkr = a; }
all variables have automatic scope. come "stack", in variables no longer valid once function returns.
named function variables can never come "heap" in sense mean it. memory named function variable tied function scope (or innermost block scope within function in variable declared).
a variable can assigned value obtained malloc()
or similar dynamic allocation function. variable points object exists in "heap". however, named pointer variable not in "heap".
sometimes "stack" dynamically allocated. such thread. then, memory used allocate function local variables running within thread in "heap". however, variables still automatic, in invalid once function returns.
Comments
Post a Comment