Click here to Skip to main content
15,935,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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

You cannot use sizeof on a parameter value to a function.
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900