When is pointer to array useful?

前端 未结 9 1677
天涯浪人
天涯浪人 2020-12-30 09:18

I can declare:

int (*ap)[N];

So ap is pointer to int array of size N. Why is this ever useful? If I pass it to function, what usefu

9条回答
  •  时光说笑
    2020-12-30 09:36

    Following code is a part of my article : Pointers and Arrays in C C++

    You can check it out @ http://pointersandarrays.blogspot.com/

    Pointers and 2D Arrays

    Following code snippet illustrates how to declare and access a 2D array. Underneath 2D Array lies a single dimensional array. You will get be sure of this after playing with the following piece of code.

    Code Snippet #4

    
     #include

    Output #4:

    Understanding Pointers and 2D Arrays  
    
    Print array using array name ...  
     0  2  4  6  8   
     1  3  5  7  9   
     2  4  6  8 10   
    
    Print array using a pointer. Proof of 1 D array being allocated ...  
    0 2 4 6 8 1 3 5 7 9 2 4 6 8 10   
    Notice that array is printed row by row in a linear fashion.  
    

提交回复
热议问题