C strcat() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
string.h

Definition

In C, strcat() copies the second string onto the end of the first. It starts writing where the old '\0' was, then writes a new ending '\0'.

You pass the destination and the source. Both are required. The destination array must already hold a C-string and still have free space for the new characters. Include <string.h>.

Syntax

Pass the destination, then the text to add. Start with this call.

C
strcat(dest, " world");
CallWhat it does
strcat(dest, " world")Adds the second text after the text already in dest.

Include <string.h>. The destination must have enough free space. This call does not grow the array.

Library declarations
C
char *strcat(char *dest, const char *src);

Parameters

ParameterDescription
destRequired. The C-string you add onto. It must already have room for the new text and a final '\0'.
srcRequired. The C-string you copy from. It is not changed.

Return Value

Return ValueDescription
dest pointerThe same destination pointer you passed in.

C Examples

Example 1 — Append One String

Join a short suffix onto an existing string. The buffer must be larger than the final result.

C
#include <stdio.h>
#include <string.h>

int main(void) {
    char dest[16] = "Hi";

    strcat(dest, "!");
    printf("%s\n", dest);

    return 0;
}

How It Works

  1. dest starts valid. "Hi" already ends with '\0'.
  2. Find the end. strcat walks to that terminator.
  3. Copy src. "!" is written over the old '\0', then a new one is added.
  4. Room matters. dest[16] easily holds "Hi!" (4 bytes including null).

Example 2 — Build a Greeting in Steps

Call strcat more than once to grow a message. Each call needs remaining capacity in the same buffer.

C
#include <stdio.h>
#include <string.h>

int main(void) {
    char msg[32] = "Hello, ";

    strcat(msg, "Sam");
    strcat(msg, "!");
    printf("%s\n", msg);

    return 0;
}

How It Works

  1. Seed the buffer. "Hello, " is the starting C-string.
  2. First append. "Sam" becomes "Hello, Sam".
  3. Second append. "!" finishes the greeting.
  4. Track length. Final size is strlen(msg) + 1; stay under 32.

Example 3 — Append Onto an Empty Buffer

An empty dest is still a valid string if the first byte is '\0'. Then strcat behaves like a copy.

C
#include <stdio.h>
#include <string.h>

int main(void) {
    char dest[16];

    dest[0] = '\0';
    strcat(dest, "Go");
    printf("%s\n", dest);

    return 0;
}

How It Works

  1. Initialize the terminator. dest[0] = '\0' makes an empty C-string.
  2. End is at index 0. Append starts writing immediately.
  3. Result is src. After the call, dest holds "Go".
  4. strcpy is clearer. For a first fill, strcpy(dest, "Go") is often simpler.

Frequently Asked Questions

strcat() appends src onto the end of dest and adds a new '\0'.
Both are required. dest is the string you add onto, and src is the text you copy from.
The same dest pointer you passed in.
Include <string.h>.
No. dest must already have enough free space.

Next: strncat()

Append with a character limit when buffer space is tight.

strncat() 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.

9 people found this page helpful