Passing a pointer representing a 2D array to a function in C++

后端 未结 5 811
别那么骄傲
别那么骄傲 2020-11-30 06:01

http://www.neilstuff.com/guide_to_cpp/notes/Multi%20Dimension%20Arrays%20and%20Pointer%20Pointers.htm

According to this site, I should be able to use the following c

5条回答
  •  一向
    一向 (楼主)
    2020-11-30 06:54

    Below is maybe your answer:

    #include 
    #include 
    
    typedef unsigned int uint;
    uint m[10][20];
    uint **ppm;
    
    int main() {
        int i;
    
        ppm = (uint **)m;
        for (i =0; i<10; ++i)ppm[i] = (uint *)&m[i];
    
        m[1][1] = 10;
    
        printf("0x%x vs 0x%x: %d vs %d\n", ppm,m, m[1][1], *(*(ppm+1)+1));
    
        return 0;
    }
    

    The result's on console screen:

    0x6010a0 vs 0x6010a0: 10 vs 10
    

提交回复
热议问题