i am assign array char type one-Dimensional Arrays to the Two-Dimensional Arrays

Hi. I am from Ukraine . sory my english.student.

below code.
If you delete this line "char symbolArray2 [5] [70] = {''};" the result of the program is not correct.
if the condition 1
//char symbolArray2 [5] [70] = {''};
as a result
ddddd
ddddd
+++++
ddddd
ddddd
ddddd

if the condition 1
char symbolArray2 [5] [70] = {''};
as a result
ddddd
ddddd
+++++
You gise of not seet
ddddd
ddddd

Why such a difference.
used by the compiler Dev-C++ 5,CodeBlock

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream> 
using namespace std; 
int main()
{
	char symbolArray[5][70] ={' '};
		char symbolArray2[5][70] ={' '};
	char  symb[50] = "You gise of not seet" ;
	char js;

		for(int i = 0; i <= 5; i++ )
	{
		for(int j = 0; j <= 30; j++ )
		{
		symbolArray[i][j] = 'd';	
		}
	}

		for(int j = 0; j <= 30; j++ )
		{
		symbolArray[2][j] = '+';	
		
		}

	for(int j = 0; j <= 30; j++ )
		{
			
		symbolArray[1][j] = symb[j];
		}
		for(int i = 0; i <= 5; i++ )
	{
		for(int j = 0; j <= 30; j++ )
		cout << symbolArray[i][j];
		cout << endl;
	}
}
In these loops

1
2
3
4
5
6
7
		for(int i = 0; i <= 5; i++ )
	{
		for(int j = 0; j <= 30; j++ )
		{
		symbolArray[i][j] = 'd';	
		}
	}

you are overwriting the memory beyond the array because the array has only rows in the range [0,4] but you are trying to fill the row 5 that does not exist in the array.
Thank you very much.
I will now carefully study the documentation, manual for the C + +.
Topic archived. No new replies allowed.