0

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...

0

1 Answer 1

2

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Or use calloc() to automatically zero the allocated memory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.