Memory Allocation

Please help me with these.

As far as I can understand.

Memory wrote:

(illustrate memories with blocks separated by "|" )

I wrote : char c;//var
Memory : | | char | |

I wrote : char c[2]//array
Memory : | | char | char | | //consecutively ?

I wrote : int f(int,char*);//function
Memory : | | int* | int | char * | //consecutively ?


Do I understand correctly ? case 3 int* is the function pointer ?

And some small questions :

- Case 2 and 3 are consecutive ?
- Case 2 should have some info to tell c contains 2 elements.Where is it ?
- Case 3 should have some info to tell f contains 2 arguments.Where is it ?
Last edited on
In case 2 the array size is not stored anywhere so your answer is correct.
Case 3 is a function declaration and will not allocate any memory at all. Not sure if this is what they are after.
How would it know c[] got 2 elements. I may only think of 2 cases : put the info somewhere else or put the terminated blocks after it.

It doesn't need to know. It is you, the programmer, that is responsible to know that.
Thanks :)
Topic archived. No new replies allowed.