I can't understand why when I'm calculating the num of elements of 'A' in main(), so the result is correct. But when I pass the 'A' to function myfunc() and calaculating there so the result is incorrect.
Can please someone explain me?

typedef struct
{
	char description[30];	
	unsigned price;	
}Car;

void myfunc(const Car A[])
{
        //The result is 0
         int i =  sizeof(A)/sizeof(A[0]);
}
void main()
{
	Car A[]={{"Fiat punto (red)", 160000},
	{"Cadilack",500000},
	{"Subaru 1600 second hand",90000},
	{"Volvo 3000 10 years old",130000},
	{"Mazda 3, 2000, from 2006", 142000}};
    
                //The result is 5
                int i = sizeof(A)/sizeof(A[0]);
}

Thank you.

It doesn't work because on line 7 the array is treated as a pointer, and the size of all pointers in 32-bit compilers is 4. If you want myfunc() to know the size of the array then it will have to be passed as another argument. void myfunc(const Car A[], int size)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.