A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
18
Task/Memory-allocation/C/memory-allocation-1.c
Normal file
18
Task/Memory-allocation/C/memory-allocation-1.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
/* size of "members", in bytes */
|
||||
#define SIZEOF_MEMB (sizeof(int))
|
||||
#define NMEMB 100
|
||||
|
||||
int main()
|
||||
{
|
||||
int *ints = malloc(SIZEOF_MEMB*NMEMB);
|
||||
/* realloc can be used to increase or decrease an already
|
||||
allocated memory (same as malloc if ints is NULL) */
|
||||
ints = realloc(ints, sizeof(int)*(NMEMB+1));
|
||||
/* calloc set the memory to 0s */
|
||||
int *int2 = calloc(NMEMB, SIZEOF_MEMB);
|
||||
/* all use the same free */
|
||||
free(ints); free(int2);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue