Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : strcpy

char *strcpy(char * dest,const char * src) ;

Return Type : char *

String pointer (array of characters)
Read about return values of strcpy function .

1st Parameter Type : char *

String pointer (array of characters)

1st Parameter

Pointer to the destination buffer where the source string will be copied.
This parameter:
•Must point to buffer large enough for source string + null terminator
•Must be writable memory
•Can not overlap with source
•Returned as function result

2nd Parameter Type : const char *

Pointer to read-only string

2nd Parameter

Pointer to the null-terminated source string to be copied.
This parameter:
•Must be null-terminated string
•Read-only (const)
•Can't be NULL
•Must not overlap with destination

Read more about parameters of strcpy in parameters section
The strcpyfunction in C language copies the source string to the destination string.
strcpy belongs to the string handling family of functions from string.h, which manipulate null-terminated strings. What makes it special is its simplicity - it performs a straightforward byte-by-byte copy until reaching a null terminator, without any bounds checking or buffer overflow protection. It's part of the basic string copying group along with strncpy and memcpy, but unlike memcpy, it specifically handles strings (stops at null) rather than raw memory blocks. The function is known for both its efficiency (direct memory copy) and its potential danger (no size checking), which led to the creation of safer alternatives like strncpy.

Key features that distinguish it:
No size parameter needed;
Returns destination pointer (enables function chaining);
Simpler than size-limited alternatives;
Considered unsafe by modern standards;
Part of original C standard library;

To Summarize the Workflow:
  1. 1.
    Copies string from source to destination including null terminator
  2. 2.
    Takes destination and source pointers as parameters
  3. 3.
    No size checking - destination must be large enough
  4. 4.
    Returns pointer to destination string
  5. 5.
    Copying stops at first null character
  6. 6.
    Source and destination must not overlap

Character Copy Process

No

Yes

strcpy(char *dest, const char *src)

Copy characters

Add null terminator

Return dest pointer

Copy next character

Is it null?

Move to next position



Read more about return type and value ofstrcpy function in return section.
The strcpyfunction takes 2 parameters:
  • char * `dest`: Pointer to the destination buffer where the source string will be copied.
    This parameter:
    •Must point to buffer large enough for source string + null terminator
    •Must be writable memory
    •Can not overlap with source
    •Returned as function result
  • const char * `src`: Pointer to the null-terminated source string to be copied.
    This parameter:
    •Must be null-terminated string
    •Read-only (const)
    •Can't be NULL
    •Must not overlap with destination
The strcpy function return value :
  • In case valid parameters passed it returns a pointer to the destination string;
    strcpy doesn't return when:
    •src is NULL pointer
    •dest is NULL pointer
    •src and dest regions overlap
    •dest buffer too small for src string
    •src not null-terminated
    •dest points to read-only memory
    •dest or src point to invalid memory addresses

    In these cases, before any return can happen:
    Program may crash;
    Memory may be corrupted;
    Buffer overflow may occur;
    System may raise segmentation fault;
    Other undefined behavior occurs;

Yes

No

strcpy(char *dest, const char *src)

Valid parameters?

Copy and return dest pointer

No return - Undefined behavior:
• NULL src pointer
• NULL dest pointer
• Overlapping regions
• Insufficient dest buffer
• Non-null-terminated src
• Read-only dest memory
• Invalid memory addresses
Results in:
• Program crash
• Memory corruption
• Buffer overflow
• Segmentation fault

Output

This example demonstrates basic usage of strcpy to copy a string from source to destination.