I read that strcpy is for copying a string, and strdup returns a pointer to a new string to duplicate the string.
strcpy
strdup
Could you please explain
strdup allocates memory for the new string on the heap, while using strcpy (or its safer strncpy varient) I can copy a string to a pre allocated memory on either the heap or the stack.
strncpy