in Programming in C
654 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

in Programming in C
654 views

4 Comments

can these type of questions be asked where ans is compiler dependent ?
0
0
in Gate, they never ask, but you have to understood which of the line implies compiler dependent, segmentation fault, undefined behaviour and implementation defined !

seems you started now, practising of C, one of the best resource is GEEKSFORGEEKS, but be aware of Syllabus in Gate of C !!
0
0
ok thanks sir
0
0

Please log in or register to answer this question.

Related questions

3 votes
3 votes
2 answers
2