Arrays in C and C++

    Arrays are simple but quite powerful constructs in C/C++. They are merely a representation of consecutive data in memory.

    They don’t contain any meta data (like size). But since they are stored in memory in such a simple manner processors can handle them very efficiently.

    //     rows  columns
    //        |  |
    //        v  v
    char data[3][2]={{0,1},
                     {2,3},
                     {4,5}};

    The values of the array data are stored row for row in memory:

    0,1,2,3,4,5

    Another possibility to see it is that multi-dimensional arrays in C/C++ are arrays of arrays.

    So data is like an array (with size 3) of arrays of char (with size 2).

    Here is a good explanation.

    The same applies to more than 2 dimensions.



    • Category

    • Programming

    • Tags

    • C
      C++

    • Created

    • 15. July 2015


    • Modified

    • 9. April 2022