You can get it with a macro:
#define sizeofa(array) sizeof array / sizeof array[ 0 ]
if and only if the array is automatic and you access it within your definition as:
#include <stdio.h> int main() { int x[] = { 1, 2, 3 }; printf("%zd\n", sizeofa( x )); return 0; }
However, if you only have a (decomposed) pointer, you cannot get the length of the array without resorting to some kind of intolerable hacking implementation.
source share