How does C Allocate Memory of Data Elements in a Multidimensional Array?

This C Tutorial Explains how Elements in a Multidimensional Array in C are Stored in Memory with an Example.

A multidimensional array can be thought of as a one-dimensional array with composite elements. For example:

  int flags[3][2][5][4]= {

Let’s presume that array ‘flags’ have three composite elements and looks like as:

    flags[3][2][5][4] = {*, *, *};

Each composite element ‘*’ is an array of 2 arrays of 5 arrays of 4 integers. Since, elements in one-dimensional array are stored in contiguous memory locations therefore with the above presumption, composite elements in ‘flags’ stored in continuous memory locations. This organisation of array elements in memory is called row major order.

Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

If you wish to look at all C Tutorials, go to C Tutorials.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.