[Solved] values of array gets changed automatically after taking string input
The problem is that you input too many characters for cin >> ch;. Since m == 40, you declared it as char ch[40]. This allows you to enter 39 characters (not 40 because of the trailing ‘\0’ character), but you entered much more than that, so it wrote outside the array boundary, which results in … Read more