2D Array Pointer Inquiry

Asked 2 years ago, Updated 2 years ago, 70 views

int **A = { {1, 2, 3, 4} {5, 6, 7 ,8} {9,10,11,12} {13,14,15,16}};

A = &A[0]

Like A+2 =&A[2]

Can I express an int** that refers to an address that corresponds to 11...?

array pointer c

2022-09-22 18:21

1 Answers

#include <stdio.h>

main(){
        int A[][4] = {
                {1, 2, 3, 4},
                {5, 6, 7 ,8},
                {9,10,11,12},
                {13,14,15,16}
        };
        int *iter = &A[0];
        printf("%d\n", *(iter + ( 4 * 2 ) + 2) );

        iter = &A[2];
        printf("%d\n", *(iter + 2));
}
int A[<2D digit>][<1D digit>];
When declaring an array, you must specify the size of the one-dimensional digit
Therefore, **A = {multidimensional array}; does not hold
In the example I have left, I left the two-dimensional space blank
It works when you do this, but the compiler doesn't specify a two-dimensional position
Spit out warning Of course, it works
Did you understand?

HYUN SUK's tag is only array and pointer, but there's no C tag Please tag c.


2022-09-22 18:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.