Difference between strdup() and strcpy()

List out differences between strdup() and strcpy()

The function strcpy() will not allocate the memory space to copy. A pointer to the string to copy and a pointer to place to copy it to should be given.

The function strdup() will occupy / grab itself the memory space for copying the string to. This memory space needs to be freed up later when it is of no use anymore.
What is the difference between char *a and char a[]?
For char[] array, such size is not accepted by the compiler. If the size is specified, the following are the differences between char *a and char a[]......
Define void pointer
A void pointer is pointer which has no specified data type. The keyword ‘void’ is preceded the pointer variable......
What is a const pointer?
A const pointer is not the pointer to constant, it is the constant. For example, int* const ptr; indicates that ptr is a pointer......a
Post your comment
Discussion Board
POSIX only
Another difference between strcpy and strdup is that strcpy is standard C and strdup is a POSIX extention. Virtually all environments have strdup though.
Martijn Lievaart 10-17-2014