Home >>C String functions >C strdup() function

C strdup() function

C strdup() function

C strdup() function are used to duplicate the given String.

Syntax:
Strdup(str)

Note:- Here str is given string.

Parameters:-

It takes string and character as parameter.

Return type:-

It returns duplicate string.

Example-1

#include <stdio.h>
#include <string.h>
int main()
{
    char *p1 = "sama";
    char *p2;
    p2 = strdup(p1);
 	printf("Duplicate string is : %s", p2);
    return 0;
}

Output:
Duplicate string is: sama

No Sidebar ads