I am currently implementing a program for file copy from one directory to another and in that program i need to allocate memory dynamically for the pointers.So is it possible to allocate memory dynamically for the array of pointers? if yes please guide me.
Thanks...
asked Apr 2, 2014 at 17:14
1 Answer 1
This dynamically allocates an array of n pointers to char:
char **p;
int n = 42;
p = malloc(n * sizeof *p);
You can then access the array like any array:
int i;
// Initialize all pointers to NULL
for (i = 0; i < n; i++)
{
p[i] = NULL;
}
answered Apr 2, 2014 at 17:16
Sign up to request clarification or add additional context in comments.
1 Comment
Digital Trauma
Or use
calloc() to automatically zero the allocated memoryExplore related questions
See similar questions with these tags.
lang-c