I’m fighting with memory managment right now. It’s verry funny for me 🙂
Here is simple app which I wrote. I can allocate memory in two ways.
int main (int argc, const char * argv[])
{
int *x;
int *z;
x = malloc(sizeof(int));
z = (int *)sizeof(int);
free(x);
free(z);
}
Is there any difference between the ways of memory allocating used in the code above ?
The second line doesn’t allocate any memory, it’s the equivalent of
ie,
zwill point to the (unallocated and most likely non-existant) (virtual) memory at address4. If you do something like:your program will crash to an access violation.