-3
1.  int minimum(int arr[]){
2.
3.     int min,pos = 0;
4.     min =  arr[0];
5.     int i;
6.     for(i = 0;i<(sizeof(arr)/sizeof(*arr));i++){
7.         if(arr[i]<min){
8.             min = arr[i];
9.             pos = i;
10.        }
11.     }
12.     return arr[pos];
13.  }

in the 6th line it the satement in the for loop condition cant count the size of the array .......

bruno
  • 32,421
  • 7
  • 25
  • 37
19mddil
  • 53
  • 8

1 Answers1

0
int minimum(int arr[])

the number of elements is unknown at compile time, sizeof(arr) cannot values the right value, it will values sizeof(int *) because this is the type of arr

But in

void f()
{
   int arr[3];

   printf("%d\n", sizeof(arr)/sizeof(*arr));
}

the sizeof of arr is known at compile time

bruno
  • 32,421
  • 7
  • 25
  • 37