#include <stdio.h>
#include <string.h>
int fashion (int[]);
main()
{
int a[]={3,2,5,1,3};
int size;
size= sizeof a/sizeof (int);
printf("size of array %d\n",sizeof(a)); //size of the array
printf("size of int %d\n",sizeof(int)); //size of the int
printf("lenght of array %d\n",size); //actual length of the array
fashion(a);
return 0;
}
int fashion(int input1[]) //tried with int fashion(int *input1)
{
int size;
size= sizeof input1/sizeof (int);
printf("\nin function\n");
printf("size of array %d\n",sizeof(input1)); //size of the array
printf("size of int %d\n",sizeof(int)); //size of the int
printf("lenght of array %d\n",size); //actual length of the array
}
Below is the output of the code:
output is
size of array 20
size of int 4
lenght of array 5
In function
size of array 8
size of int 4
lenght of array 2
Both the code in main function and function called are same but resulting different results.
Why the size of the array is changed in main function it is 20 and in the function it is 8? who can i make both the results same?
I even tried with Fashion(int input1[]) but resulting in same.