when does a array act as a pointer in c?

后端 未结 5 735
盖世英雄少女心
盖世英雄少女心 2021-01-15 08:34

i know that the array name could be used as a pointer(although it\'s a converted form), but my question is , Is there some other instance where array acts as a pointer.

5条回答
  •  别那么骄傲
    2021-01-15 09:07

    The identifier itself tells the base address of the memory block.
    
    int arr[SIZE];
    
     arr
    +------+------+----       ----+------+
    |      |      |     . . .     |      |
    +------+------+----       ----+------+
     arr[0] arr[1]  arr[2]  arr[n-1] arr[n]
    
    
    
    The `arr' holds the address of the base address of the block
    
    int *arr = malloc (sizeof (int) * SIZE);
    
     arr
    +------+
    |addr1 |------------+
    +------+            |
    addr_of_arr         |
                        |
                        |
                        V
                      +------+------+----       ----+------+
                      |      |      |     . . .     |      |
                      +------+------+----       ----+------+
                      addr1[0] addr[1]    addr1[n-1] addr1[n]
    

提交回复
热议问题