Problem undestanding pointer arithmetic

Hi in this excerpt of a code:

for(int j = 1 ; j < myImage.rows-1; ++j)
     const uchar* previous = myImage.ptr<uchar>(j - 1);
     const uchar* current  = myImage.ptr<uchar>(j    );
     const uchar* next     = myImage.ptr<uchar>(j + 1);
     uchar* output = Result.ptr<uchar>(j);
     for(int i= nChannels;i < nChannels*(myImage.cols-1); ++i)
         output[i] = saturate_cast<uchar>(5*current[i]
                      -current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]);

Shouldn’t on the line of output being assigned to a new value the current, previous and next pointers and even output have an asterisk before them so the actual value they point is taken?

I am got this from this example: OpenCV: Mask operations on matrices

Please help and thanks in advance!

output[i] is equivalent to *(output + i)

In the first you are using the array index operator [] to access an element in an array. C-style arrays and pointers are very similar, so you can use the array index operator on a pointer to access the pointed-to data (at some offset).

You can also access the pointed-to data with the pointer dereference operator as you have suggested, but the array index method is cleaner in my opinion.

Hi Steve, thanks! I thought so.