1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
// Same IN MEMORY as the 3D array shown previously.
int array[24] = { 100, 101, 102, 103,
104, 105, 106, 107,
108, 109, 110, 111,
112, 113, 114, 115,
116, 117, 118, 119,
120, 121, 122, 123 };
// Could also be declared with all but the first dimension specified in declaration.
// int array[][3][4] = { // OKAY
// If I give you code that accesses a multi-dimensional array,
// you should be able to give a declaration and initialization
// that would make that code work.
printf("array[0][2][3] == %d\n", array[(0 * 3 * 4) + (2 * 4) + (3)]);
return EXIT_SUCCESS;
}
/*
OUTPUT:
array[0][2][3] == 111
*/
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2017 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.