Tag Archives: malloc

implementing malloc in C

12 Feb
#include<stdio.h>
void* Malloc(int );
main(){
int size = 16;
int *a = NULL;
a = (int *)Malloc(size);
int i = 0;
for(i = 0; i < 4; i ++){
a[i] = i;
printf(“a[%d] = %d\n”,i,i);
}
}
void* Malloc(int size) {
int s = size/sizeof(char);
int array[s];
int i = 0;
for(i = 0; i < s; i ++){
array[i] = NULL;
}
return (void *)array;
}
Follow

Get every new post delivered to your Inbox.