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.

Categories:
less than a minute
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;
}
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.