#include <iostream>
#include <cstring>
using namespace std;
int main() {
char sor[6] = "hello";
char des[6] = "hello";
strcat(des,sor);
cout << des;
}
When i start the debugging of the program it gives the following error along with the console output (behind it) :

why is it so ? If there is anything wrong with the code ,please give a suggestion
While increasing the size of the
stringchar-array would help you in this situation, let me propose to actually use C++ features; don’t code C when you want to code C++:Why not char arrays
Suhail asked why char-arrays are bad:
One shouldn’t be using char-arrays because of situations like exactly this. Many more dangerous situations exist; effectively, when you are using C arrays, there’s a certain danger that your program is subject to buffer-overflow attacks.
You were actually very lucky that you directly received the exception; but more often than you like those bugs are subtle and don’t uncover themselves for days, months, years; and then, possibly, your customer will be in in the daily news for being cracked and losing their customers credit card information into the public.
Using C++ facilities like
stringorstringstream, this can be avoided easily.