C | Arrays | Question 3

What is output?

filter_none

edit
close

play_arrow

link
brightness_4
code

# include <stdio.h>
  
void print(int arr[])
{
   int n = sizeof(arr)/sizeof(arr[0]);
   int i;
   for (i = 0; i < n; i++)
      printf("%d ", arr[i]);
}
  
int main()
{
   int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
   print(arr);
   return 0;
}

chevron_right


(A) 1, 2, 3, 4, 5, 6, 7, 8
(B) Compiler Error
(C) 1 2
(D) Run Time Error


Answer: (C)

Explanation: See http://www.geeksforgeeks.org/using-sizof-operator-with-array-paratmeters/ for explanation.

Quiz of this Question



My Personal Notes arrow_drop_up

Improved By : rvarun11



Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.