Click here to Skip to main content
14,267,085 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to find the length of an array using the sizeof method, but I get this error


helpers.c:22:16: error: sizeof on array function parameter will return size of 'int *' instead of 'int []' [-Werror,-Wsizeof-array-argument] n = sizeof(values)/sizeof(int); ^ helpers.c:17:29: note: declared here
bool search(int value, int values[], int n)

Thanks,

What I have tried:

bool search(int value, int values[], int n)
{
n = sizeof(values)/sizeof(int);
}
Posted
Updated 28-Dec-16 5:59am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You cannot use sizeof on a parameter value to a function.
   
Comments
Ramza360 28-Dec-16 12:10pm
   
This is the correct solution.. You cannot use that in C due to sizeof being a compile time pointer. I've deleted my solution as I did not realize it was just a C related question.
CPallini 28-Dec-16 15:55pm
   
Exactly. 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100