Retrieve Data from a Two-Dimensional Array uses pointer - C Array

C examples for Array:Multidimensional Arrays

Description

Retrieve Data from a Two-Dimensional Array uses pointer

Demo Code

#include <stdio.h>

int main()//from  www . ja v a2  s  .  co m
{
     int num[3][2] = {
                       {1, 4},
                       {2, 5},
                       {3, 6}
                     };
     int (*ptrArray) [2];
     int *ptrInt;
     for(int row = 0; row < 3; row++){
        ptrArray = &num[row];
        ptrInt = (int *) ptrArray;
        for(int col = 0; col < 2; col++)
           printf("%d    ", *(ptrInt + col));
        printf("\n");
     }
    
     return(0);
}

Result


Related Tutorials