Thursday, 22 August 2013

Some questions about memory/malloc

Some questions about memory/malloc

How are variables really stored in memory? I ask this because say you
malloc a segment of memory and assign it to a pointer e.g.
int *p = malloc(sizeof(10*int));
and then run a for loop to assign integers through p - this seems
different to declaring an int variable and assigning an integer to it
like:
int x = 10;
Because it's a more explicit declaration that you want an int stored in
memory, whereas in malloc it's just a chunk of memory you're traversing
through pointer arithmetic.
Am I missing something here? Much thanks.

No comments:

Post a Comment