Declaration is all about just knowing the data type.
It is enough to know that, it is an array of int and it will return int .
So both statements will work same.
Run the below code:
#include <stdio.h>
// Function declaration: int fun(int arr[])
int fun(int arr[])
{
int sum = 0;
int i;
// Calculate the sum of array elements
for (i = 0; arr[i] != '\0'; i++)
{
sum += arr[i];
}
return sum;
}
// Function declaration: int fun(int arr[2])
int fun2(int arr[2])
{
int sum = 0;
int i;
// Calculate the sum of array elements
for (i = 0; arr[i] != '\0'; i++)
{
sum += arr[i];
}
return sum;
}
int main()
{
int arr1[] = {1, 2, 3, 4, 5}; // Array of any size
// Call the first function
int result1 = fun(arr1);
printf("Result 1: %d\n", result1);
// Call the second function
int result2 = fun2(arr1);
printf("Result 2: %d\n", result2);
return 0;
}
OUTPUT:
Result1: 15
Result2: 15