C language 2D array address and reference to value

Asked 1 years ago, Updated 1 years ago, 117 views

Hello, I am a student studying programming, and I have a question while studying C language.

int array[2][2] = {10,20,30,40}; Assuming that this arrangement exists, when you do printf("%x", array+1); The address value of the first line is printed out, right? But printf("%x", *(array+1); I also don't know why the address value is printed... If array+1 is an address value, shouldn't *(array+1) output the value in the memory indicated by the address?

c 2d-array pointer

2022-09-21 14:17

1 Answers

A two-dimensional array is a double (double) pointer. So array is a double pointer.

Only the address value is output because *(array+1) is the pointer to the pointer.

Handle must be done as below.

*(*(array + 0) + 0)  // 10
*(*(array + 1) + 0)  // 30


2022-09-21 14:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.