Combining 2 variables of type char in C++

Combining 2 variables of type char in C++

June 27, 2024·İbrahim Korucuoğlu
İbrahim Korucuoğlu

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;
}
Last updated on