Page 53 - C-Language
P. 53

A 3D array is essentially an array of arrays of arrays: it's an array or collection of 2D arrays, and a
        2D array is an array of 1D arrays.




















        3D array memory map:







        Initializing a 3D Array:


         double cprogram[3][2][4]={
         {{-0.1, 0.22, 0.3, 4.3}, {2.3, 4.7, -0.9, 2}},
          {{0.9, 3.6, 4.5, 4}, {1.2, 2.4, 0.22, -1}},
          {{8.2, 3.12, 34.2, 0.1}, {2.1, 3.2, 4.3, -2.0}}
         };


        We can have arrays with any number of dimensions, although it is likely that most of the arrays
        that are created will be of one or two dimensions.


        Iterating through an array using pointers



         #include <stdio.h>
         #define SIZE (10)
         int main()
         {
             size_t i = 0;
             int *p = NULL;
             int a[SIZE];

             /* Setting up the values to be i*i */
             for(i = 0; i < SIZE; ++i)
             {
                 a[i] = i * i;
             }

             /* Reading the values using pointers */
             for(p = a; p < a + SIZE; ++p)
             {
                 printf("%d\n", *p);
             }

             return 0;
         }





        https://riptutorial.com/                                                                               29
   48   49   50   51   52   53   54   55   56   57   58