strcat() Append one string to another

strcat() Append one string to another

strcat() appends src over the old terminator and writes a new one. The buffer needs both lengths plus one byte; the strings must not overlap.

Categorystring.h strings
KindLibrary function
Header<string.h>
C standardC89 / C90

📝 Syntax

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

⚙️ Parameters

dest RequiredA writable null-terminated destination with enough remaining capacity.
src RequiredThe null-terminated source string to append.

Returns: Returns dest.

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

Hello, C!
⚠️ Warning The destination capacity must hold the original length, appended length, and final null character. Overlapping dest and src causes undefined behavior.
💡 Tip The example reserves space for the terminator with strlen(text) + strlen(suffix) < sizeof text.

📚 Related Tutorials

❓ FAQ

QHow large must the destination buffer be for strcat?
AIt needs at least strlen(dest) + strlen(src) + 1 bytes, with the final byte reserved for the new terminator.
QDoes strcat preserve the destination's original null terminator?
ANo. It begins overwriting at that position with the source string and writes a new null character after the combined result.
QWhy can repeatedly appending many strings with strcat become progressively slower?
AEach strcat call scans the destination to find its end. As the destination grows, repeatedly scanning from the beginning makes the total work grow quadratically. Track the current length or an end pointer instead; after confirming sufficient total capacity, write new content directly at the end and update the terminator.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏