5 ms·
You're right, but it only works for fixed-sized arrays (which are not as common). Also for a learner it is very easy to think that I can do: int * my_array
by raverbashing 4y ago
You're right, but it only works for fixed-sized arrays (which are not as common). Also for a learner it is very easy to think that I can do:
int * my_array;
my_array = malloc(100*sizeof(int));
int array_length = sizeof(my_array);
- enriquto 4y ago> it only works for fixed-sized arrays It also works for variable length arrays. void f(int n) { float a[n]; int m = sizeof a / sizeof *a; assert(n == m); }
- kevin_thibedeau 4y agoIn this case my_array isn't an array. Misleading learners that arbitrary blocks of memory are "arrays" is the bigger travesty.