Question: I've noticed in many examples/tutorials that people use the brace operator "()" for matrix access, which is confusing for me in some cases.

The question is:
Let's assume we have a n\*m matrix (3x4, for example) named M. What elements will be returned by accessing it via "M(0)", or "M(1)", or any other singular parameter inside the braces? I thought that you are supposed to specify both the row and the column (like "M(0,1)" or something like that).

Answer: 
What you see there is **linear index access** - namely directly accessing the memory in a linear way.

In a matrix, all elements are stored in one big block of memory, each row following after the previous one. This is why, if you want to access an element at the position `(i, j)` you write somethink like

```
elem = matrix(j + rowWidth*i)

```

But you could simply access it as 

```
elem = matrix(k)

```

This is useful when you don't care about the row/col position, by example when you sum up all the elements in a matrix:

```
count = width*height;
sum=0;
for(i=0;i<count;i++)
    sum+=matrix(i);

```

Or when you have precalculated linear indices.

Beware that this technique can create some of the craziest bugs if the matrix happen not to be stored in a continuous block of memory - by example a region of interest in a bigger matrix. Always check `if (myMat.isContinuous())` before using linear indices!
This is from OpenCV 2.4.2

```
template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int i0, int i1)
{
    return ((_Tp*)(data + step.p[0]*i0))[i1];
}
template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int i0)
{
    return this->at<_Tp>(i0);
}
template<typename _Tp> inline _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2)
{
    return this->at<_Tp>(i0, i1, i2);
}

```

and this is definition for `Mat::at(int i0)` which `Mat_` publicly inherits from `Mat`

```
template<typename _Tp> inline const _Tp& Mat::at(int i0) const
{
    if( isContinuous() || size.p[0] == 1 )
        return ((const _Tp*)data)[i0];
    if( size.p[1] == 1 )
        return *(const _Tp*)(data + step.p[0]*i0);
    int i = i0/cols, j = i0 - i*cols;
    return ((const _Tp*)(data + step.p[0]*i))[j];
}

```