Z
Zach
Could someone please illustrate this with some ANSI C code?
Zach
Zach
Could someone please illustrate this with some ANSI C code?
Do you mean implemented a stack and a heap, or how some runtimeZach said:Could someone please illustrate this with some ANSI C code?
The former can be addressed in any good book or Google search. The
latter does not have anything to do with ANSI C, I think.
Ah, been reading some posts in here and see heap and stack mentioned.
I have a vague understanding of what they are. Thought there was way
to illustrate this with some code in C.
Could someone please illustrate this with some ANSI C code?
Zach
Rachael said:Could someone please illustrate this with some ANSI C code?
Zach
If you just declare a variable or array like this:
int n;
char ac[5];
then it's on the stack.
When it goes out of scope (i.e. when you exit
the function or block in which it was declared) the memory which it
took up is automatically given back.
If you allocate memory using malloc, like this:
char * pc = malloc(5);
then the memory is allocated on the heap, and will not automatically
be given back when the variable goes out of scope, so you have to
explicitly free the memory:
free(pc);
Zach said:Could someone please illustrate this with some ANSI C code?
Zach said:To answer Clever Monkey:
I was thinking about the latter: "the stack" and "the heap".
Never saw or learned the former either: "stack" and "heap" in C
yet
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.