how to accept an array as function parameter in c

Solutions on MaxInterview for how to accept an array as function parameter in c by the best coders in the world

showing results for - "how to accept an array as function parameter in c"
Nicolò
12 Aug 2017
1#include <stdio.h>
2void displayNumbers(int num[2][2]);
3int main()
4{
5    int num[2][2];
6    printf("Enter 4 numbers:\n");
7    for (int i = 0; i < 2; ++i)
8        for (int j = 0; j < 2; ++j)
9            scanf("%d", &num[i][j]);
10
11    // passing multi-dimensional array to a function
12    displayNumbers(num);
13    return 0;
14}
15
16void displayNumbers(int num[2][2])
17{
18    printf("Displaying:\n");
19    for (int i = 0; i < 2; ++i) {
20        for (int j = 0; j < 2; ++j) {
21           printf("%d\n", num[i][j]);
22        }
23    }
24}