![]() |
VOOZH | about |
A 3D array (or three-dimensional array) in C is a multi-dimensional array that contains multiple layers of two-dimensional arrays stacked on top of each other. It stores elements that can be accessed using three indices: the depth index, row index, and column index. In this article, we will learn how to pass a 3D array to a function in C.
We cannot directly pass a to a function just like we do . Instead, we must pass the 3D array to function as a pointer. When doing so, the array undergoes , losing information about its dimensions. Therefore, we must pass the dimensions of the array separately.
functionType funcName(type (*arr)[cols][depth], int rows, int cols, int depth)Here,
The following program illustrates how we can pass a 3D array to a function in C.
Elements of the 3D array: 10 20 30 40 50 60 70 80 90 1 2 3 4 5 6 7 8 9 190 200 210 220 230 240 250 260 270
Time Complexity: O(1), as the time complexity of passing is not dependent on array size.
Auxiliary Space: O(1)