I am looking to find out if I initialized this array correctly because when I display it it does not display what I thought it should display. Here is the code:
#include <iostream>
#include <string.h>
void Pause()
{
std::cin.get();
std::cin.ignore();
}
int main()
{
int n = 0;
int size;
std::cout << "Enter what width you want the board to be: ";
std::cin >> size;
int **p_p_Board;
p_p_Board = new int*[size];
//Loops for initializing array
for (int i = 0; i < size; i++)
{
p_p_Board[i] = new int[size];
}
for (int i = 0; i < size; i++)
{
for (int j = 0; i < size; i++)
{
//Initializing Array
p_p_Board[i][j] = 0;
}
}
//Display loops
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
//Displaying the array
std::cout << p_p_Board[i][j];
n++;
if (n == size)
{
std::cout << std::endl;
n = 0;
}
}
}
Pause();
for (int i = 0; i < size; i++)
{
delete [] p_p_Board[i];
}
delete p_p_Board;
}
And here is the display:
Enter what width you want the board to be: 8
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
0-842150451-842150451-842150451-842150451-842150451-842150451-842150451
As you can see it prints the number -842150451 after the first number in each row. While the first number in each row is correctly set to 0, the rest are not. Is this correct or do I have an error in my code?