R
R
ReD2015-10-06 23:45:42
Programming
ReD, 2015-10-06 23:45:42

What value is obtained after denaming the pointer?

Please explain how to dereference a pointer
in a string

*(ptr+i*B+j)

in such code
int DIM[A][B];
  int *ptr = (int *) DIM;
  for (int i=0; i<A; i++)
    {
      for (int j=0; j<B; j++)
      {
        cout << setw(4) << *(ptr+i*B+j) << endl;
      }
      cout << endl;
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-10-07
@trinitr0

For pointers (type *), adding/subtracting an integer moves the pointer forward/backward by the size of the sizeof(type) element.

int A[3];
int *ptr = A; // ptr указывает на A[0]
ptr += 2; // ptr указывает на A[2]
ptr --; // ptr указывает на A[1]
ptr = ptr+10; // ptr указывает за пределы массива A

M
Maxim Moseychuk, 2015-10-07
@fshp

DIM[i][j]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question