Combining 2 variables of type char in C++

Estimated read time 1 min read

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 << '\n';
    cout << "Second string: " << secondString << '\n';

    strcat(firstString, secondString);

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

    return 0;
}
İbrahim Korucuoğlu

Yazar, bilişim ve teknoloji alanında derlediği faydalı içerikleri bu blogta paylaşmaktadır.