When I create a 2-dimensional vector in c++ such as
vector < vector<int> > matrix(3, vector<开发者_StackOverflowint>(4));
would matrix[2][3] be accessible or would matrix[3][2] be accessible?
You created the first dimension as 3 and the second as 4. That means that matrix[3]
is out of bounds. The other way around, though, would be fine- and would be fine regardless of which is which.
matrix[3][2]
does not make sense since you have defined your matrix as 3x4 and you're trying to access element (4,3)
. If your question is regarding the access syntax, it's matrix[row_no][col_no]
where the indices start from 0.
精彩评论