-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray-as-function.c
45 lines (40 loc) · 921 Bytes
/
array-as-function.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
int function1(int array[])
{
for (int i = 0; i < 4; i++)
{
printf("The value of %d is %d\n", i, array[i]);
}
array[0] = 13465; // If we change the value here then it will also change in the main.
return 0;
}
void function2(int *ptra)
{
for (int i = 0; i < 4; i++)
{
printf("The value of %d is %d\n", i, ptra[i]);
}
*(ptra + 2) = 4589;
}
void function3(int array[2][2])
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
printf("The value at %d, %d is %d\n", i, j, array[i][j]);
}
}
}
int main()
{
int arr[] = {23, 123, 134, 34};
printf("The value of first array is %d\n", arr[0]);
function1(arr);
printf("The value of first array is %d\n", arr[0]);
function2(arr);
function2(arr);
int array[][2] = {{23, 123}, {5, 14}};
function3(array);
return 0;
}