What Is The Difference Between Strdup And Strcpy?


1 Answers

Arlene Fernandes Profile
The strcpy function implies copying a string to a specific location which you, yourself have created. That is, you create the location as well as make sure that your source string will have a sufficient amount of room available and then use strcpy in order to copy.

On the other hand, strdup implies copying a string to a particular location that will be automatically created by the function. In this case it is the function which allocates adequate space, making sure that the string will actually fit there and then copies the string. It returns a pointer to the area which has been newly created.

C is an essential, general-purpose, procedural computer programming language which was first developed at the Bell Telephone Laboratories in the year 1972 by Dennis Ritchie.

Answer Question