C++ strcat() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
<cstring>

Definition

In C++, strcat() joins two C-strings. It copies the second string onto the end of the first, starting where the old '\0' was, then writes a new '\0'.

Both strings are required. The first array must already have free space for the added characters and that new '\0'. strcat() does not grow the array, and the two strings must not overlap. Include <cstring>.

Syntax

The first string is the one that grows. The second string is copied onto its end.

C++
strcat(dest, "C++");
CallWhat it does
strcat(dest, "C++")Adds C++ onto the end of dest.
Library declarations
C++
char* strcat(char* destination, const char* source);

Parameters

ParameterDescription
destRequired. The C-string you add onto. It must already have room for the new characters.
sourceRequired. The C-string you copy from. It is not changed.

Return Value

Return ValueDescription
destThe same pointer you passed in. It now holds both strings.

C++ Examples

Example 1 — Basic strcat()

Append "World!" onto "Hello ".

C++
#include <iostream>
#include <cstring>

int main() {
    char dest[50] = "Hello ";
    const char* src = "World!";

    strcat(dest, src);

    std::cout << dest << '\n';
    return 0;
}

How It Works

  1. dest starts as "Hello " (with room left in the array).
  2. strcat finds the end of dest and copies src there.
  3. Result: "Hello World!" ending with '\0'.

Example 2 — Append More Than Once

Call strcat again to keep building one buffer.

C++
#include <iostream>
#include <cstring>

int main() {
    char message[80] = "C++";

    strcat(message, " ");
    strcat(message, "Tutorial");

    std::cout << message << '\n';
    return 0;
}

How It Works

  1. First call appends a space.
  2. Second call appends "Tutorial".
  3. Keep the array big enough for every append.

Example 3 — Safer Style with std::string

Same idea without managing a fixed buffer yourself.

C++
#include <iostream>
#include <string>

int main() {
    std::string text = "Hello ";
    text += "World!";

    std::cout << text << '\n';
    return 0;
}

How It Works

  1. std::string grows as needed.
  2. += appends like strcat, but safer for beginners.
  3. Learn strcat for C-style APIs; prefer std::string in new C++.

Frequently Asked Questions

strcat() adds one C-string onto the end of another and writes a new null character at the end.
dest is the string you add onto. source is the string you copy from. source is not changed.
The same pointer as dest, which now holds both strings.
Big enough for the old text, the new text, and one ending null character. strcat() does not grow the array.
No. Overlapping source and destination is not allowed.

Next: strchr()

Find the first occurrence of a character in a C-string.

strchr() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful