C programming....1


#include <stdio.h>
void fun(int arr[])
int i;
unsigned int n = sizeof(arr)/sizeof(arr[0]);
for (i=0; i<n; i++)
printf("%d ", arr[i]);

// Driver program
int main()
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
return 0;


When we pass an array to a function say fun(), it is always treated as a pointer by fun(). So sizeof(arr) will be 4 and sizeof(arr[0]) will return the size of integer depending upon the machine.


in above program, all elements of array will get printed. as sizeof(arr)/size(arr[0]) will give
(total size of array)/(size of element) which equals to the total number of the element.

so the output will be, 1 2 3 4 5 6 7 8


NO u are wrong because when we pass array as argument to another function .it just behaves as pointer to that array.so size of(arr)=size of pointer which is 4.and size of(a[0])depends on machine if it is 32 bit then 2 byte ,in 64 bit it is 4 byte.hence n=4/2=2 or n=4/4=1.so either 1 element will be printed or 2 element will be printed.


Sizeof(arr) means here the size of the pointer and sizeof(arr[0]) means the size of the value present in the array at position 0.So all elements will not be printed.