I need to allocate memory for a pointer which needs to be used as a 2d array.I know how to allocate memory for char pointers and int pointers I am confused how memory is allocat
What you're doing is allocating space for 5 chars. You could write this and it'll have the same result:
char *names = (char *)malloc(sizeof(char) * 5);
If you want to have an array of pointers, I think this'd be the best code
char **names = (char **)malloc(sizeof(char *) * 5);
I'm not a super-coder, but as what I now, this is the right solution.