C program to pass two dimensional array (Two-D array) to a function
Given a two dimensional array and we have to pass it to the function in C.
In this example, we are declaring a two dimensional array inside the main() function and passing it to the function - within the function, elements of the array are printing.
Here is the function that we are using in the program,
void arrayfun(int ptr[3][3] , int row, int col)
Here,
- void is the return type of the function.
- arrayfun is the name of the function.
- int ptr[3][3] an integer type of variable (which is declared as two dimensional array), that will store the elements of the array which will be passed. We can also use int ptr[][3] there is no need to provide size for the row, but number of maximum columns must be provided.
- int row, int col are the variables that will store the value of number of rows and columns.
Function calling statement,
arrayfun(array,3,3);
Program to pass two dimensional arrays in C
Output
need an explanation for this answer? contact us directly to get an explanation for this answer