Pointers: Difference between revisions

wikademia>Rantir
→Advanced Pointers: Added basic example of doing a malloc to a block of memory
wikademia>Rantir
→Advanced Pointers: Minor formatting
Line 248: Line 248:
scanf("%d", &size);
scanf("%d", &size);
uchar *data;
uchar *data;
/* Check to make sure a NULL pointer wasn't returned from malloc */
/* Check to make sure a NULL pointer wasn't returned from malloc */
if ((data = (uchar*) malloc(size)) == NULL)
if ((data = (uchar*) malloc(size)) == NULL)
Line 271: Line 272:
if ((data = (uchar*) malloc(size)) == NULL)
if ((data = (uchar*) malloc(size)) == NULL)
exit(1);
exit(1);
/* Raw data after second malloc. Shows how there can be stuff 'left over'
/* Raw data after second malloc. Shows how there can be stuff 'left over'
* in memory after malloc call*/
* in memory after malloc call*/