Referencing a specific element of a bidimensional matrix via the pointer notation [closed]

1

C allows you to treat each row of a two-dimensional array as a one-dimensional array.

As known, one way to reference two-dimensional arrays in the form of pointers in C is, for example:

tabela[j][k] = *(*(tabela + j) + k)

According to my book the handouts:

Let's assume that the array array address is 1000, so table == 1000 and that table is an array [4] [5]

As a table is an integer array, each element occupies 4 bytes in this case. We have 5 elements in each line, so each line occupies 20 bytes. Because each row is an array of one dimension, each array of a dimension begins 20 bytes after the previous

Therefore, table + 1 takes the table address (1000) and adds the number of bytes of the line (5 columns times 4 bytes per column, resulting 20 bytes)

So, table + 1 is interpreted as address 1020, which is the address of the second array of a dimension of the array, table + 2 is the address of the third and so on

How do I reference an individual element on the line?

The array address is the same as the address of the first array element. It is already determined that the address of the array formed by the third line is table [2] or table + 2 in pointer notation.

The address of the first element of this array formed by the third line is & table [2] [0] or * (table + 2) in pointer notation. Therefore, table + 2 and * (table + 2) would reference the same address, in this case, 1040.

However, as far as I know of pointers, the * operator deferentially returns the contents of a pointed address. Considering that table + 2 is an address, so * (table + 2) should return the contents / value for which this address points, not 1040.

So, technically, the expression

tabela[j][k] = *(*(tabela + j) + k) 

It would not make sense, because * (table + j) should return a value, not an address.

My question is why the expressions table + 2 and * (table + 2) would reference the same address, the first one should return an address and the second the value of this address

    
asked by anonymous 11.11.2018 / 18:12

0 answers