C strdup() Function

Last Updated:

C strdup()

The strdup() function duplicates a given string at the allocated memory which is pointed by a pointer variable.

Example

C Compiler
#include <stdio.h> #include <string.h> int main() { char *orgstr = "wikimass.com"; char *dupstr; // Create a duplicate string dupstr = strdup(orgstr); printf("Duplicated string: %s", dupstr); return 0; }

Syntax

char *strdup(const char *str)

Parameter Values

ValueTypeExplanation
str Required Specifies a string to be duplicated.

Return Value

ValueExplanation
String Returns a duplicate string.

Share this Page

Meet the Author