how free of memory happen in this case???
Posted
by Riyaz
on Stack Overflow
See other posts from Stack Overflow
or by Riyaz
Published on 2010-05-03T06:27:21Z
Indexed on
2010/05/03
6:38 UTC
Read the original article
Hit count: 202
#include <stdio.h>
void func(int arr[],int xNumOfElem)
{
int j;
for(j=0; j<xNumOfElem; j++)
{
arr[j] = j + arr[j];
printf("%d\t",arr[j]);
}
printf("\n");
}
int main()
{
int *a,k;
a = (int*) malloc(sizeof(int)*10);
for(k = 0; k<10; k++)
{
a[k] = k;
printf("%d\t",a[k]);
}
printf("\n");
func(a,10); //Func call
free(a);
}
Inside the the function "func" who will allocate/deallocate memory for dynamic array "arr".
arr is an function argument.
© Stack Overflow or respective owner