615 views
0 votes
0 votes

 

    
#include <stdio.h>
// Note that arr[] for fun is just a pointer even if square
// brackets are used
void fun(char arr[])  // SAME AS void fun(int *arr)
{
   unsigned int n = sizeof(arr)/sizeof(arr[0]);
   printf("\nArray size inside fun() is %d", n);
}

// Driver program
int main()
{
   char  arr[] = {"hiten"};
   unsigned int n = sizeof(arr)/sizeof(arr[0]);
  printf("Array size inside main() is %d", n);
   fun(arr);
   return 0;
}


 ****************************

output is confusing : need explaination how is it happening

Array size inside main() is 6

Array size inside fun() is 8

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
1
Nitesh Choudhary asked Apr 16, 2017
477 views
There are many questions related to size of pointer and it's also depend on machine so anyone tell me source of reading pointer. (for Gate)
3 votes
3 votes
2 answers
2
0 votes
0 votes
1 answer
3