Combining 2 variables of type char in C++

In this example, you can see how to combine 2 char variables with a length of 50 characters using the strcat method.

In this example, you can see how to combine 2 char variables with a length of 50 characters using the strcat method.

#include <iostream>
#include <cstring>
using namespace std;

int main() {
    constexpr size_t bufferSize = 50;
    char firstString[bufferSize] = "abc";
    char secondString[bufferSize] = "def";

    cout << "First string: " << firstString << ' ';
    cout << "Second string: " << secondString << ' ';

    strcat(firstString, secondString);

    cout << "Concatenated string: " << firstString << ' ';

    return 0;
}
Last modified 17.01.2025: new translations (f32b526)