# how to fill a specific column in a 2d array

• ### Question

• array[6][7]

I want to fill for example the second column in the 2d array

Wednesday, April 4, 2012 10:25 AM

• array[6][7]

I want to fill for example the second column in the 2d array

What second *array*? You have one array, with two
dimensions. These can be thought of as row and column.

array[0][1] // address 1st row, 2nd col
array[1][1] // address 2nd row, 2nd col
array[2][1] // address 3rd row, 2nd col
etc.

You really need to do some reading. There should be no
need for you to ask such rudimentary questions here.
We can't teach someone how to program in these forums.

PTRTUT03.TXT
"A Tutorial on Pointers and Arrays in C"

- Wayne

• Marked as answer by Thursday, April 12, 2012 1:33 AM
Wednesday, April 4, 2012 11:38 AM
• You have to traverse upto the location where you want to fill the data. That's why i asked you to pick some book on C/C++ . First you should understand the concept of array and then go for further operation with array.A Simple example

```int main()
{
int somevalue =3;
int board[9][9]; //creates a 9*9 matrix or a 2d array.
for(int i=0; i<9; i++)    //This loops on the rows.
{
for(int j=0; j<9; j++) //This loops on the columns
{
board[i][j] = somevalue
}
}
return 0;
} ```

Thanks

Rupesh Shukla

• Marked as answer by Thursday, April 12, 2012 1:33 AM
Wednesday, April 4, 2012 2:28 PM

### All replies

• array[6][7]

I want to fill for example the second column in the 2d array

What second *array*? You have one array, with two
dimensions. These can be thought of as row and column.

array[0][1] // address 1st row, 2nd col
array[1][1] // address 2nd row, 2nd col
array[2][1] // address 3rd row, 2nd col
etc.

You really need to do some reading. There should be no
need for you to ask such rudimentary questions here.
We can't teach someone how to program in these forums.

PTRTUT03.TXT
"A Tutorial on Pointers and Arrays in C"

- Wayne

• Marked as answer by Thursday, April 12, 2012 1:33 AM
Wednesday, April 4, 2012 11:38 AM
• You have to traverse upto the location where you want to fill the data. That's why i asked you to pick some book on C/C++ . First you should understand the concept of array and then go for further operation with array.A Simple example

```int main()
{
int somevalue =3;
int board[9][9]; //creates a 9*9 matrix or a 2d array.
for(int i=0; i<9; i++)    //This loops on the rows.
{
for(int j=0; j<9; j++) //This loops on the columns
{
board[i][j] = somevalue
}
}
return 0;
} ```

Thanks

Rupesh Shukla

• Marked as answer by Thursday, April 12, 2012 1:33 AM
Wednesday, April 4, 2012 2:28 PM
• ```rows = sizeof array / sizeof *array;
col = 1; /* first column is 0 */
for (i = 0; i < rows; i++)
array[i][col] = 42;```

Wednesday, April 4, 2012 6:17 PM