A little understanding of two-dimensional arrays and pointers

#include <stdio.h>
int main(void)
{
    
    
    
    int num[4][2];
    num;
    num[0];
    return 0;
}

Let me discuss the difference between num and num[0]. According to my analysis, both of them represent addresses. I will use num[4][2] to visualize and understand

Insert picture description here
This should be the storage mode of the two-dimensional array in space.

num
num[0]
There is a little difference between the two, although the address of the first element stored is the address of num[0][0], but the two represent different

num, num+1, num+2
are the addresses representing the size of two int types, that is,
num[0], num[1], num[2] represents the address of the first element of this row , Represents an address of type int.
However, &num[0] is equal to num. Represents this row, representing an array.

A two-dimensional array can be regarded as two arrays, the rows are accessed first, then the columns. First enter the row array, and then enter the column array according to the address stored in the row array. Only numbers or elements are stored in the column array.

num is a secondary pointer.
First *num, represents the solution application, enter this row of array, and then solve the application
num again , extract the number stored in the address of the first element of the array, or treat it as
( (num+0)+0), the brackets inside represent The first element of which array is outside the parentheses is the first element, which has the same meaning as num[0][0].

This is mainly to discuss the storage mode of a two-dimensional array in memory.
If there is an error, please give advice.
There is more.
Advanced pointer-ONE

Guess you like

Origin blog.csdn.net/weixin_52199109/article/details/111415765