2D array of zeros

I want to create a 2D array of zeros. Can I do this or do I need to use a loop?

 
  int numbers[ROWS][COLUMNS] = {0};
Why don't you check it yourself by using a loop?
1
2
3
4
5
6
for (int i=0;i<ROWS;i++)
   {
   for(int j=0;j<COLUMNS;j++)
   cout<<numbers[ROW][COLUMNS][i][j];

   }


if the output is all zeroes then obviously you can use that...

hope it helps
Last edited on
Good idea. I checked it and the values weren't zeros, so I'll just assign each element zero using a loop. Thanks for your help.
the code
int numbers[ROWS][COLUMNS] = {0};
works for me in windows and Code::blocks IDE with GCC compiler.

try again.
@cpp1024

Sorry to say, but shadder's loop is NOT correct. It should be..
1
2
3
4
5
for (int i=0;i<ROWS;i++)
{
   for(int j=0;j<COLUMNS;j++)
   cout<<numbers[i][j]; // Use i and j, NOT ROWS, and COLUMNS
 }


To zero your 2D array when you create it, use int numbers[ROWS][COLUMNS] = {{0},{0}};

Use just the single zero, as you already had, when creating a 1D array
+1 whitenite1

my bad... edited accordingly
Thank you for your help!
@cpp1024

You're welcome...
Topic archived. No new replies allowed.