I know that malloc for pointers to get a place in mamory but how does it work?
I know that malloc for pointers to get a place in mamory but how does it work?
This probably would be a thread better placed on the C board. As to your question, do you wish to know how to use the malloc function, or do you wish to know how it is implememented on a given platform?
int x;
x = 5;
the pointer equivelance:
int *p = malloc(sizeof(int));
*x = 5;
if you did:
x = 5;
with the pointer, you would overwrite the memory returned from malloc and replace it with a 5. That is why you need to dereference it (*x) first, to assign to memory returned from malloc a value, and not replace the memory itself.