Two Dimensional Array Implementation Using Double Pointer

前端 未结 5 999
生来不讨喜
生来不讨喜 2020-12-07 17:14

Please consider the following code:

#include 
#include 

#define NUM_ARRAYS     4
#define NUM_ELEMENTS   4
#define INVALID_VAL         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 17:42

    *ptr + 1 is address of ptr[0][1]

    Because, we know

    ptr[0][1] == *(*(ptr+0)+1)
    

    Now putting ampersand on both side

    &ptr[0][1] == &*(*(ptr+0)+1)
    

    You know that ampersand with asterisk is like plus sign with minus sign? They get cancelled. So this becomes

    &ptr[0][1] == (*(ptr+0)+1)
    

    Which is same as

    &ptr[0][1] == *(ptr+0)+1
    

    Which is again same as

    &ptr[0][1] == *ptr+1
    

    This is my first statement.

提交回复
热议问题