Multi-dimensional array: Difference between revisions

Added output section for C
(Added output section for C)
Line 141:
 
=={{header|C}}==
{{Output?}}
C supports multi-dimensional arrays, and thanks to the inter-op of arrays and points in C, it is possible to target any section of memory and drill down to the bit level. C uses row-major order for storing arrays. There are many ways to declare arrays, or pointers which can then be used as arrays, as shown below :
<lang C>/*Single dimensional array of integers*/
Line 210 ⟶ 209:
}
</lang>
{{Output?}} :
<pre>
abhishek_ghosh@Azure:~/stuff/Rosettacode$ ./a.out
 
1
1
</pre>
Declared as above or by using the functions malloc or calloc of the C Standard Library, memory is allocated contiguously. This obviously assumes that the machine has sufficient memory. The following implementation shows how a multi pointer can work as an array :
<lang C>
Line 279 ⟶ 285:
return 0;
}</lang>
Output :
<pre>
abhishek_ghosh@Azure:~/stuff/Rosettacode$ ./a.out
 
1
1
</pre>
C does not do bound checking / range checking or for that matter any type of safety check. C Programmers are supposed to know what they are doing, the code can access any part of memory and as long as nothing prevents it, as in the OS, anti virus etc, the program will get hold of that memory. Of course, this means that the program can seriously damage itself, other programs, the machine and anything connected to it, but use it properly and you can write things such as Linux. Reallocation is possible via realloc but it is buggy and data corruption is possible. Linked lists are a much better option.
 
503

edits