I have a question about getting the length of an array in C. I always get the result 1. This result probably comes from the fact, that int is 4 bytes big, and 4 / 4 = 1. So the problem is that I dont get the size of the whole array, only of a single value in it.
Here is my code:
#include <stdio.h> int getArrayLength(int array[]); int main() { int myArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; printf("Length of array is: %d", getArrayLength(myArray)); return 0; } int getArrayLength(int array[]) { int size = (int) sizeof(*array) / sizeof(array[0]); return size; }
Maybe someone can help me fixing my problem.
Thank you^^