PDA

View Full Version : I need help with Memory Allocation in C



CT_Bolt
December 16th, 2006, 20:46
Information:
I know how to dynamically allocate and free memory in C++

Problem:
I tried to dynamically allocate memory in C and it doesn't support these 2 functions:
new, delete

Question:
How do i write this code in C?

int *x;
x = new int[5];
delete [] x;
x = 0;

MikeDX
December 16th, 2006, 22:22
int *x;

x=(int *)malloc(sizeof(int)*5);

free(x);

CT_Bolt
December 16th, 2006, 22:59
Thank you much MikeDX!

This is exactly what I was looking for. :thumbup: