M
M
mrCraick2019-01-30 19:28:28
C++ / C#
mrCraick, 2019-01-30 19:28:28

How to organize pointers in C?

Hello!
I write in pure C and met with a problem.
I have a dynamic two dimensional array.
I need to pass it to the function, but when the pointer is mixed by +1 to fill the second cell, an access violation exception occurs when reading at the address.
I tried to simplify everything and the same thing comes out, the code is below.

int test[2];

int *y = test;
int **t = &y;
int ***h = &t;

**h[1] = 0;  //нарушение прав доступа при чтении по адресу 0xCCCCCCCC.

What am I doing wrong, or is it impossible to work with a pointer to a pointer to a pointer in si vprintsepe?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2019-01-30
@Mercury13

The point here is the order of operations.
First, the right one-place ones are calculated, then the left ones.
It is necessary (**h)[1] = 0;.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question