# Thread: Change column in matrix

1. ## Change column in matrix

Hello,

I got matrix 3x3
Code:
```double matrix[3][3]={{0}, {0}, {0}};
double vector[3]={7,7,7};```
how to put the vector on the first column of my matrix?
do I understand correctly that matrix[0] is an adress to the first column?
i would like to change the adress of first column to the adress of the vector.

2. Originally Posted by plasticstone
Hello,

I got matrix 3x3
Code:
```double matrix[3][3]={{0}, {0}, {0}};
double vector[3]={7,7,7};```
how to put the vector on the first column of my matrix?
Use a for loop and assign every element of vector to the corresponding elements of matrix:
Code:
`matrix[0][i] = vector[i];`
do I understand correctly that matrix[0] is an adress to the first column?
Yes, that's correct, but arrays are not modifiable values. matrix[0] is an array of 3 doubles (remember, it's a 2-d array). Thus you can't change where matrix[0] points.

i would like to change the adress of first column to the adress of the vector.
Like I said, you can't change the address of the first column. You would need a 1-d array of pointers (double *matrix[3]; ) to do that, but it's not a very good approach. It will become very difficult to keep track of what's in matrix.

3. Originally Posted by plasticstone
Hello,
how to put the vector on the first column of my matrix?
It depends on how do you interpret rows and columns but:
Code:
```int i;

for (i = 0; i < 3; i++){
matrix[i][0] = vector[i];
}```

Originally Posted by plasticstone
do I understand correctly that matrix[0] is an adress to the first column?
Again, "It depends on how do you interpret rows and columns", but since C is row-major, no matrix[0] is the address of the first row.

Originally Posted by plasticstone
i would like to change the adress of first column to the adress of the vector.
You can't do that, not in this way. Using an array of pointers is a workaround, but not a pretty one.