When passing an array as an argument to a function, a fixed array decays into a pointer, and the pointer is passed to the function.
#include <stdio.h>
#include <string.h>
void fun(char *arr)
{
int i;
unsigned int n = sizeof(arr); //This will give size of pointer. On different machines it can be a different size(on mine Its 4)
printf("n = %d\n", n); // n=4
for (i=0; i<n; i++)
printf("%c ", arr[i]);
}
int main()
{
char arr[] = {'k', 'h', 'u', 's', 'h', 'a', 'l'};
fun(arr);
return 0;
}
output will be
4
k h u s